adium 5904:ad40ec511e77: Obtain the user's email automatically, ...
commits at adium.im
commits at adium.im
Wed Apr 1 11:21:32 UTC 2015
details: http://hg.adium.im/adium/rev/ad40ec511e77
revision: 5904:ad40ec511e77
branch: GoogleOAuth2
author: Thijs Alkemade <me at thijsalkema.de>
date: Wed Apr 01 13:21:11 2015 +0200
Obtain the user's email automatically, and set that as the JID.
diffs (60 lines):
diff -r 680a579a4b3c -r ad40ec511e77 Plugins/Purple Service/AIPurpleGTalkAccount.m
--- a/Plugins/Purple Service/AIPurpleGTalkAccount.m Wed Apr 01 12:37:07 2015 +0200
+++ b/Plugins/Purple Service/AIPurpleGTalkAccount.m Wed Apr 01 13:21:11 2015 +0200
@@ -120,7 +120,7 @@
account:self.UID
keychainItem:NULL error:NULL];
- if (refresh_token) {
+ if (refresh_token && refresh_token.length) {
[self useRefreshToken:refresh_token];
} else {
[self requestAccessToken];
@@ -190,13 +190,33 @@
}
- (void)connectionDidFinishLoading:(NSURLConnection *)inConnection {
- NSError *error = nil;
- NSDictionary *responseDict = [response objectFromJSONDataWithParseOptions:JKParseOptionNone error:&error];
+ NSDictionary *responseDict = [response objectFromJSONData];
AILogWithSignature(@"%@", responseDict);
[[adium accountController] setPassword:[responseDict objectForKey:@"access_token"] forAccount:self];
+ if (!self.UID.length) {
+ NSString *jsonWebToken = [responseDict objectForKey:@"id_token"];
+
+ if (!jsonWebToken) {
+ AILogWithSignature(@"id_token missing, can't set JID!");
+ } else {
+ NSArray *components = [jsonWebToken componentsSeparatedByString:@"."];
+
+ if (components.count == 3) {
+ NSData *identityData = [[NSData alloc] initWithBase64EncodedString:[[components objectAtIndex:1] stringByAppendingString:@"=="] options:NSDataBase64DecodingIgnoreUnknownCharacters];
+ NSDictionary *identity = [identityData objectFromJSONData];
+
+ AILogWithSignature(@"%@", identity);
+
+ [self filterAndSetUID:[identity objectForKey:@"email"]];
+
+ [identityData release];
+ }
+ }
+ }
+
if ([responseDict objectForKey:@"refresh_token"]) {
[[AIKeychain defaultKeychain_error:NULL] deleteGenericPasswordForService:self.service.serviceID
account:self.UID
diff -r 680a579a4b3c -r ad40ec511e77 Plugins/Purple Service/AIPurpleGTalkAccountViewController.m
--- a/Plugins/Purple Service/AIPurpleGTalkAccountViewController.m Wed Apr 01 12:37:07 2015 +0200
+++ b/Plugins/Purple Service/AIPurpleGTalkAccountViewController.m Wed Apr 01 13:21:11 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"
+ @"scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgoogletalk%20email"
@"&redirect_uri=urn:ietf:wg:oauth:2.0:oob"
@"&response_type=code"
@"&client_id=" ADIUM_GTALK_CLIENT_ID;
More information about the commits
mailing list