adium 5901:f84e4565f51c: access_token and refresh_token are now ...

commits at adium.im commits at adium.im
Wed Apr 1 09:51:58 UTC 2015


details:	http://hg.adium.im/adium/rev/f84e4565f51c
revision:	5901:f84e4565f51c
branch:		GoogleOAuth2
author:		Thijs Alkemade <me at thijsalkema.de>
date:		Wed Apr 01 11:51:37 2015 +0200

access_token and refresh_token are now obtained.

diffs (92 lines):

diff -r 422e6c62f68e -r f84e4565f51c Plugins/Purple Service/AIPurpleGTalkAccountViewController.h
--- a/Plugins/Purple Service/AIPurpleGTalkAccountViewController.h	Wed Apr 01 10:49:48 2015 +0200
+++ b/Plugins/Purple Service/AIPurpleGTalkAccountViewController.h	Wed Apr 01 11:51:37 2015 +0200
@@ -22,6 +22,9 @@
 	IBOutlet NSTextField *label_grant;
 	IBOutlet NSTextField *label_code;
 	IBOutlet NSButton *button_submit;
+	
+	NSMutableData *response;
+	NSURLConnection *conn;
 }
 
 -(IBAction)requestAccess:(id)sender;
diff -r 422e6c62f68e -r f84e4565f51c Plugins/Purple Service/AIPurpleGTalkAccountViewController.m
--- a/Plugins/Purple Service/AIPurpleGTalkAccountViewController.m	Wed Apr 01 10:49:48 2015 +0200
+++ b/Plugins/Purple Service/AIPurpleGTalkAccountViewController.m	Wed Apr 01 11:51:37 2015 +0200
@@ -16,7 +16,10 @@
 
 #import "AIPurpleGTalkAccountViewController.h"
 
+#import "JSONKit.h"
+
 #define ADIUM_GTALK_CLIENT_ID @"853036734951.apps.googleusercontent.com"
+#define ADIUM_GTALK_SECRET @"TSXNUaq34k_0YU7DZT4HbmQd"
 
 @implementation AIPurpleGTalkAccountViewController
 
@@ -24,6 +27,13 @@
 	return @"ESPurpleGTalkAccountView";
 }
 
+- (void)dealloc {
+	[response release];
+	[conn release];
+	
+	[super dealloc];
+}
+
 - (void)awakeFromNib
 {
 	[super awakeFromNib];
@@ -74,7 +84,49 @@
 }
 
 - (IBAction)submit:(id)sender {
-	NSLog(@"Token: %@", textField_code.value);
+	NSLog(@"Token: %@", textField_code.stringValue);
+	
+	NSString *body = [NSString stringWithFormat:@"code=%@&client_id=" ADIUM_GTALK_CLIENT_ID
+					  @"&client_secret=" ADIUM_GTALK_SECRET
+					  @"&redirect_uri=urn:ietf:wg:oauth:2.0:oob"
+					  @"&grant_type=authorization_code", textField_code.stringValue];
+	
+	NSData *data = [body dataUsingEncoding:NSUTF8StringEncoding];
+	
+	NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://www.googleapis.com/oauth2/v3/token"]];
+	[request setHTTPMethod:@"POST"];
+	[request setValue:@"application/x-www-form-urlencoded ; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
+	[request setValue:[NSString stringWithFormat:@"%u", (unsigned int)[data length]] forHTTPHeaderField:@"Content-Length"];
+	[request setHTTPBody:data];
+	
+	AILogWithSignature(@"%@", request);
+	
+	conn = [[NSURLConnection connectionWithRequest:request delegate:self] retain];
+	
+	response = [[NSMutableData alloc] init];
+}
+
+- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)urlResponse {
+	AILogWithSignature(@"%@", urlResponse);
+}
+
+- (void)connection:(NSURLConnection *)inConnection didReceiveData:(NSData *)data {
+	[response appendData:data];
+}
+
+- (void)connectionDidFinishLoading:(NSURLConnection *)inConnection {
+//	NSString *responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
+	
+//	NSLog(@"%@", responseString);
+	
+	NSError *error = nil;
+	NSDictionary *responseDict = [response objectFromJSONDataWithParseOptions:JKParseOptionNone error:&error];
+	
+	AILogWithSignature(@"%@", responseDict);
+}
+
+-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
+	AILogWithSignature(@"did fail");
 }
 
 @end




More information about the commits mailing list