adium 5906:8fc11ca97010: Fix the base64 decoding, use the bare J...

commits at adium.im commits at adium.im
Wed Apr 1 13:15:35 UTC 2015


details:	http://hg.adium.im/adium/rev/8fc11ca97010
revision:	5906:8fc11ca97010
branch:		GoogleOAuth2
author:		Thijs Alkemade <me at thijsalkema.de>
date:		Wed Apr 01 15:15:17 2015 +0200

Fix the base64 decoding, use the bare JID of the user.

diffs (94 lines):

diff -r da95f3976785 -r 8fc11ca97010 Plugins/Purple Service/AIPurpleGTalkAccount.m
--- a/Plugins/Purple Service/AIPurpleGTalkAccount.m	Wed Apr 01 14:05:03 2015 +0200
+++ b/Plugins/Purple Service/AIPurpleGTalkAccount.m	Wed Apr 01 15:15:17 2015 +0200
@@ -116,14 +116,18 @@
 
 - (void)connect
 {
-	NSString *refresh_token = [[AIKeychain defaultKeychain_error:NULL] findGenericPasswordForService:self.service.serviceID
-																							 account:self.UID
-																						keychainItem:NULL error:NULL];
-	
-	if (refresh_token && refresh_token.length) {
-		[self useRefreshToken:refresh_token];
+	if (!self.UID.length) {
+		[self requestAccessToken];
 	} else {
-		[self requestAccessToken];
+		NSString *refresh_token = [[AIKeychain defaultKeychain_error:NULL] findGenericPasswordForService:self.service.serviceID
+																								 account:self.UID
+																							keychainItem:NULL error:NULL];
+		
+		if (refresh_token && refresh_token.length) {
+			[self useRefreshToken:refresh_token];
+		} else {
+			[self requestAccessToken];
+		}
 	}
 }
 
@@ -203,7 +207,23 @@
 			NSArray *components = [jsonWebToken componentsSeparatedByString:@"."];
 		
 			if (components.count == 3) {
-				NSData *identityData = [[NSData alloc] initWithBase64EncodedString:[[components objectAtIndex:1] stringByAppendingString:@"=="] options:NSDataBase64DecodingIgnoreUnknownCharacters];
+				NSString *base64EncodedIdentity = [components objectAtIndex:1];
+				
+				// Restore the padding
+				switch (base64EncodedIdentity.length % 4) {
+					case 2: {
+						base64EncodedIdentity = [base64EncodedIdentity stringByAppendingString:@"=="];
+						break;
+					}
+					case 3: {
+						base64EncodedIdentity = [base64EncodedIdentity stringByAppendingString:@"="];
+						break;
+					}
+					default: {
+					}
+				}
+				
+				NSData *identityData = [[NSData alloc] initWithBase64EncodedString:base64EncodedIdentity options:NSDataBase64DecodingIgnoreUnknownCharacters];
 				NSDictionary *identity = [identityData objectFromJSONData];
 				
 				AILogWithSignature(@"%@", identity);
@@ -215,6 +235,11 @@
 		}
 	}
 	
+	if (!self.UID.length) {
+		[self setLastDisconnectionError:@"Obtaining your JID failed"];
+		return;
+	}
+	
 	if ([responseDict objectForKey:@"refresh_token"]) {
 		[[AIKeychain defaultKeychain_error:NULL] deleteGenericPasswordForService:self.service.serviceID
 																		 account:self.UID
diff -r da95f3976785 -r 8fc11ca97010 Plugins/Purple Service/AIPurpleGTalkAccountViewController.m
--- a/Plugins/Purple Service/AIPurpleGTalkAccountViewController.m	Wed Apr 01 14:05:03 2015 +0200
+++ b/Plugins/Purple Service/AIPurpleGTalkAccountViewController.m	Wed Apr 01 15:15:17 2015 +0200
@@ -57,7 +57,7 @@
 
 - (IBAction)requestAccess:(id)sender {
 	NSString *urlString = @"https://accounts.google.com/o/oauth2/auth?"
-	@"scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgoogletalk%20email"
+	@"scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgoogletalk%20https://www.googleapis.com/auth/userinfo.email"
 	@"&redirect_uri=urn:ietf:wg:oauth:2.0:oob"
 	@"&response_type=code"
 	@"&client_id=" ADIUM_GTALK_CLIENT_ID;
diff -r da95f3976785 -r 8fc11ca97010 Plugins/Purple Service/libpurple_extensions/auth_gtalk.c
--- a/Plugins/Purple Service/libpurple_extensions/auth_gtalk.c	Wed Apr 01 14:05:03 2015 +0200
+++ b/Plugins/Purple Service/libpurple_extensions/auth_gtalk.c	Wed Apr 01 15:15:17 2015 +0200
@@ -42,10 +42,11 @@
 	xmlnode_set_attrib(auth, "mechanism", "X-OAUTH2");
 	xmlnode_set_attrib(auth, "auth:service", "oauth2");
 	xmlnode_set_attrib(auth, "xmlns:auth", "http://www.google.com/talk/protocol/auth");
+	xmlnode_set_attrib(auth, "auth:client-uses-full-bind-result", "true");
 	
 	resp = g_string_new("");
 	resp = g_string_append_c(resp, '\0');
-	resp = g_string_append(resp, js->user->node);
+	resp = g_string_append(resp, jabber_id_get_bare_jid(js->user));
 	resp = g_string_append_c(resp, '\0');
 	resp = g_string_append(resp, purple_connection_get_password(js->gc));
 	




More information about the commits mailing list