From a78d06ea01d5717282ed524171992537ab11bc7c Mon Sep 17 00:00:00 2001 From: Anton Kozlovskij Date: Mon, 19 Jul 2021 20:36:28 +0300 Subject: [PATCH 1/4] fix calling callback on addScopes --- GoogleSignIn/Sources/GIDSignIn.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/GoogleSignIn/Sources/GIDSignIn.m b/GoogleSignIn/Sources/GIDSignIn.m index 4da4beff..8a4dd42f 100644 --- a/GoogleSignIn/Sources/GIDSignIn.m +++ b/GoogleSignIn/Sources/GIDSignIn.m @@ -690,10 +690,11 @@ - (void)addCompletionCallback:(GIDAuthFlow *)authFlow { [authFlow addCallback:^() { GIDAuthFlow *handlerAuthFlow = weakAuthFlow; if (self->_currentOptions.callback) { - dispatch_async(dispatch_get_main_queue(), ^{ - self->_currentOptions.callback(self->_currentUser, handlerAuthFlow.error); + GIDSignInCallback callback = [self->_currentOptions.callback copy]; self->_currentOptions = nil; - }); + dispatch_async(dispatch_get_main_queue(), ^{ + callback(self->_currentUser, handlerAuthFlow.error); + }); } }]; } From ddcdeee7c80f3294b704e26c03901dd7de582cbf Mon Sep 17 00:00:00 2001 From: Anton Kozlovskyi Date: Mon, 19 Jul 2021 21:17:16 +0300 Subject: [PATCH 2/4] Add possibility to choose scopes in time of sign in --- GoogleSignIn/Sources/GIDSignIn.m | 14 ++++++++++++ .../Sources/GIDSignInInternalOptions.h | 6 +++++ .../Sources/GIDSignInInternalOptions.m | 15 ++++++++++++- .../Sources/Public/GoogleSignIn/GIDSignIn.h | 22 +++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/GoogleSignIn/Sources/GIDSignIn.m b/GoogleSignIn/Sources/GIDSignIn.m index 4da4beff..538b2e43 100644 --- a/GoogleSignIn/Sources/GIDSignIn.m +++ b/GoogleSignIn/Sources/GIDSignIn.m @@ -192,6 +192,20 @@ - (void)signInWithConfiguration:(GIDConfiguration *)configuration [self signInWithOptions:options]; } +- (void)signInWithConfiguration:(GIDConfiguration *)configuration + presentingViewController:(UIViewController *)presentingViewController + hint:(nullable NSString *)hint + scopes:(nullable NSArray *)scopes + callback:(nullable GIDSignInCallback)callback { + GIDSignInInternalOptions *options = + [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration + presentingViewController:presentingViewController + loginHint:hint + scopes:scopes + callback:callback]; + [self signInWithOptions:options]; +} + - (void)signInWithConfiguration:(GIDConfiguration *)configuration presentingViewController:(UIViewController *)presentingViewController callback:(nullable GIDSignInCallback)callback { diff --git a/GoogleSignIn/Sources/GIDSignInInternalOptions.h b/GoogleSignIn/Sources/GIDSignInInternalOptions.h index fed207f3..46385cfd 100644 --- a/GoogleSignIn/Sources/GIDSignInInternalOptions.h +++ b/GoogleSignIn/Sources/GIDSignInInternalOptions.h @@ -55,6 +55,12 @@ NS_ASSUME_NONNULL_BEGIN loginHint:(nullable NSString *)loginHint callback:(GIDSignInCallback)callback; ++ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration + presentingViewController:(nullable UIViewController *)presentingViewController + loginHint:(nullable NSString *)loginHint + scopes:(nullable NSArray *)scopes + callback:(GIDSignInCallback)callback; + /// Creates the options to sign in silently. + (instancetype)silentOptionsWithCallback:(GIDSignInCallback)callback; diff --git a/GoogleSignIn/Sources/GIDSignInInternalOptions.m b/GoogleSignIn/Sources/GIDSignInInternalOptions.m index 7f233383..2a65ce36 100644 --- a/GoogleSignIn/Sources/GIDSignInInternalOptions.m +++ b/GoogleSignIn/Sources/GIDSignInInternalOptions.m @@ -23,6 +23,7 @@ @implementation GIDSignInInternalOptions + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration presentingViewController:(nullable UIViewController *)presentingViewController loginHint:(nullable NSString *)loginHint + scopes:(nullable NSArray *)scopes callback:(GIDSignInCallback)callback { GIDSignInInternalOptions *options = [[GIDSignInInternalOptions alloc] init]; if (options) { @@ -32,11 +33,23 @@ + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)con options->_presentingViewController = presentingViewController; options->_loginHint = loginHint; options->_callback = callback; - options->_scopes = [GIDScopes scopesWithBasicProfile:@[]]; + options->_scopes = [GIDScopes scopesWithBasicProfile:scopes]; } return options; } ++ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration + presentingViewController:(nullable UIViewController *)presentingViewController + loginHint:(nullable NSString *)loginHint + callback:(GIDSignInCallback)callback { + GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:configuration + presentingViewController:presentingViewController + loginHint:loginHint + scopes:@[] + callback:callback]; + return options; +} + + (instancetype)silentOptionsWithCallback:(GIDSignInCallback)callback { GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:nil presentingViewController:nil diff --git a/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h b/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h index d8fc9c8f..feb791c4 100644 --- a/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h +++ b/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h @@ -124,6 +124,28 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error); hint:(nullable NSString *)hint callback:(nullable GIDSignInCallback)callback; +/// Starts an interactive sign-in flow using the provided configuration and a login hint. +/// +/// The callback will be called at the end of this process. Any saved sign-in state will be +/// replaced by the result of this flow. Note that this method should not be called when the app is +/// starting up, (e.g in `application:didFinishLaunchingWithOptions:`); instead use the +/// `restorePreviousSignInWithCallback:` method to restore a previous sign-in. +/// +/// @param configuration The configuration properties to be used for this flow. +/// @param presentingViewController The view controller used to present `SFSafariViewContoller` on +/// iOS 9 and 10. +/// @param hint An optional hint for the authorization server, for example the user's ID or email +/// address, to be prefilled if possible. +/// @param scopes a list of initial scopes +/// @param callback The `GIDSignInCallback` block that is called on completion. This block will be +/// called asynchronously on the main queue. + +- (void)signInWithConfiguration:(GIDConfiguration *)configuration + presentingViewController:(UIViewController *)presentingViewController + hint:(nullable NSString *)hint + scopes:(nullable NSArray *)scopes + callback:(nullable GIDSignInCallback)callback; + /// Starts an interactive consent flow to add scopes to the current user's grants. /// /// @param scopes The scopes to ask the user to consent to. From cba34eb068d07356509dcce47a4bfb3f5b69d6ce Mon Sep 17 00:00:00 2001 From: Anton Kozlovskyi Date: Mon, 19 Jul 2021 22:14:33 +0300 Subject: [PATCH 3/4] fixes due review --- GoogleSignIn/Sources/GIDSignIn.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/GoogleSignIn/Sources/GIDSignIn.m b/GoogleSignIn/Sources/GIDSignIn.m index 8a4dd42f..b0caa52d 100644 --- a/GoogleSignIn/Sources/GIDSignIn.m +++ b/GoogleSignIn/Sources/GIDSignIn.m @@ -390,9 +390,9 @@ - (void)signInWithOptions:(GIDSignInInternalOptions *)options { [self authenticateWithOptions:options]; } else { if (options.callback) { + self->_currentOptions = nil; dispatch_async(dispatch_get_main_queue(), ^{ options.callback(self->_currentUser, nil); - self->_currentOptions = nil; }); } } @@ -522,9 +522,9 @@ - (void)authenticateWithOptions:(GIDSignInInternalOptions *)options { code:kGIDSignInErrorCodeHasNoAuthInKeychain userInfo:nil]; if (options.callback) { + self->_currentOptions = nil; dispatch_async(dispatch_get_main_queue(), ^{ options.callback(nil, error); - self->_currentOptions = nil; }); } return; @@ -690,11 +690,11 @@ - (void)addCompletionCallback:(GIDAuthFlow *)authFlow { [authFlow addCallback:^() { GIDAuthFlow *handlerAuthFlow = weakAuthFlow; if (self->_currentOptions.callback) { - GIDSignInCallback callback = [self->_currentOptions.callback copy]; - self->_currentOptions = nil; - dispatch_async(dispatch_get_main_queue(), ^{ - callback(self->_currentUser, handlerAuthFlow.error); - }); + GIDSignInCallback callback = self->_currentOptions.callback; + self->_currentOptions = nil; + dispatch_async(dispatch_get_main_queue(), ^{ + callback(self->_currentUser, handlerAuthFlow.error); + }); } }]; } From 01976611497dfcb8de8a285049476c16ce0e8664 Mon Sep 17 00:00:00 2001 From: Peter Andrews Date: Tue, 8 Mar 2022 00:12:24 -0800 Subject: [PATCH 4/4] Complete merge from main --- GoogleSignIn/Sources/GIDSignIn.m | 1 + GoogleSignIn/Sources/GIDSignInInternalOptions.h | 3 ++- GoogleSignIn/Sources/GIDSignInInternalOptions.m | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/GoogleSignIn/Sources/GIDSignIn.m b/GoogleSignIn/Sources/GIDSignIn.m index 9b7dde04..c5505ed0 100644 --- a/GoogleSignIn/Sources/GIDSignIn.m +++ b/GoogleSignIn/Sources/GIDSignIn.m @@ -226,6 +226,7 @@ - (void)signInWithConfiguration:(GIDConfiguration *)configuration [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration presentingViewController:presentingViewController loginHint:hint + addScopesFlow:NO scopes:scopes callback:callback]; [self signInWithOptions:options]; diff --git a/GoogleSignIn/Sources/GIDSignInInternalOptions.h b/GoogleSignIn/Sources/GIDSignInInternalOptions.h index 739fce91..b01110a4 100644 --- a/GoogleSignIn/Sources/GIDSignInInternalOptions.h +++ b/GoogleSignIn/Sources/GIDSignInInternalOptions.h @@ -63,8 +63,9 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration presentingViewController:(nullable UIViewController *)presentingViewController loginHint:(nullable NSString *)loginHint + addScopesFlow:(BOOL)addScopesFlow scopes:(nullable NSArray *)scopes - callback:(GIDSignInCallback)callback; + callback:(nullable GIDSignInCallback)callback; /// Creates the options to sign in silently. + (instancetype)silentOptionsWithCallback:(GIDSignInCallback)callback; diff --git a/GoogleSignIn/Sources/GIDSignInInternalOptions.m b/GoogleSignIn/Sources/GIDSignInInternalOptions.m index 106c0aba..35e56a28 100644 --- a/GoogleSignIn/Sources/GIDSignInInternalOptions.m +++ b/GoogleSignIn/Sources/GIDSignInInternalOptions.m @@ -45,7 +45,7 @@ + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)con presentingViewController:(nullable UIViewController *)presentingViewController loginHint:(nullable NSString *)loginHint addScopesFlow:(BOOL)addScopesFlow - callback:(GIDSignInCallback)callback { + callback:(nullable GIDSignInCallback)callback { GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:configuration presentingViewController:presentingViewController loginHint:loginHint