adium/adium

ad40ec511e77
Parents 680a579a4b3c
Children da95f3976785
Obtain the user's email automatically, and set that as the JID.
--- 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
--- 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;