From cf97879a9e61f7ad0a2b18fb2c2dba202d8a2935 Mon Sep 17 00:00:00 2001 From: Dean Canlas Date: Thu, 10 Dec 2015 15:01:17 +0800 Subject: [PATCH] Adds access_type parameter for GoogleWeb provider --- .../SimpleAuthGoogleWebLoginViewController.m | 3 ++- .../GoogleWeb/SimpleAuthGoogleWebProvider.m | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Pod/Providers/GoogleWeb/SimpleAuthGoogleWebLoginViewController.m b/Pod/Providers/GoogleWeb/SimpleAuthGoogleWebLoginViewController.m index 146ad6c..b3d6ac4 100644 --- a/Pod/Providers/GoogleWeb/SimpleAuthGoogleWebLoginViewController.m +++ b/Pod/Providers/GoogleWeb/SimpleAuthGoogleWebLoginViewController.m @@ -25,7 +25,8 @@ - (NSURLRequest *)initialRequest { @"client_id" : self.options[@"client_id"], @"redirect_uri" : self.options[SimpleAuthRedirectURIKey], @"response_type" : @"code", - @"scope" : self.options[@"scope"] + @"scope" : self.options[@"scope"], + @"access_type": self.options[@"access_type"] }; NSString *URLString = [NSString stringWithFormat: @"https://accounts.google.com/o/oauth2/auth?%@", diff --git a/Pod/Providers/GoogleWeb/SimpleAuthGoogleWebProvider.m b/Pod/Providers/GoogleWeb/SimpleAuthGoogleWebProvider.m index 3bf070d..f0aeb8d 100644 --- a/Pod/Providers/GoogleWeb/SimpleAuthGoogleWebProvider.m +++ b/Pod/Providers/GoogleWeb/SimpleAuthGoogleWebProvider.m @@ -41,6 +41,7 @@ + (NSDictionary *)defaultOptions { options[SimpleAuthPresentInterfaceBlockKey] = presentBlock; options[SimpleAuthDismissInterfaceBlockKey] = dismissBlock; options[SimpleAuthRedirectURIKey] = @"http://localhost"; + options[@"access_type"] = @"online"; options[@"scope"] = @"email openid profile"; return options; } @@ -96,12 +97,19 @@ - (void)userWithCode:(NSString *)code completion:(SimpleAuthRequestHandler)compl NSString *token = dictionary[@"access_token"]; if ([token length] > 0) { - NSDictionary *credentials = @{ - @"access_token" : token, - @"expires" : [NSDate dateWithTimeIntervalSinceNow:[dictionary[@"expires_in"] doubleValue]], - @"token_type" : @"bearer", - @"id_token": dictionary[@"id_token"] - }; + NSMutableDictionary *credentials = [NSMutableDictionary new]; + NSDictionary *defaultCredentials = @{ + @"access_token" : token, + @"expires" : [NSDate dateWithTimeIntervalSinceNow:[dictionary[@"expires_in"] doubleValue]], + @"token_type" : @"bearer", + @"id_token": dictionary[@"id_token"] + }; + + [credentials addEntriesFromDictionary:defaultCredentials]; + if (dictionary[@"refresh_token"]) { + NSDictionary *refreshToken = @{ @"refresh_token": dictionary[@"refresh_token"] }; + [credentials addEntriesFromDictionary:refreshToken]; + } [self userWithCredentials:credentials completion:completion]; @@ -153,10 +161,7 @@ - (NSDictionary *)dictionaryWithAccount:(NSDictionary *)account dictionary[@"provider"] = [[self class] type]; // Credentials - dictionary[@"credentials"] = @{ - @"token" : credentials[@"access_token"], - @"expires_at" : credentials[@"expires"] - }; + dictionary[@"credentials"] = credentials; // User ID dictionary[@"uid"] = account[@"id"]; @@ -190,6 +195,7 @@ - (NSDictionary *)dictionaryWithAccount:(NSDictionary *)account dictionary[@"info"] = user; + return dictionary; }