Просмотр исходного кода

Adds a flag to indicate the auth flow is restarting.

This avoids the completion handlers being invoked prematurely which precludes the auth flow from being restarted because of the cleaning up of internal states.
Xiangtian Dai 4 лет назад
Родитель
Сommit
3bf36c1748
1 измененных файлов с 10 добавлено и 0 удалено
  1. 10 0
      GoogleSignIn/Sources/GIDSignIn.m

+ 10 - 0
GoogleSignIn/Sources/GIDSignIn.m

@@ -146,6 +146,8 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
   OIDServiceConfiguration *_appAuthConfiguration;
   OIDServiceConfiguration *_appAuthConfiguration;
   // AppAuth external user-agent session state.
   // AppAuth external user-agent session state.
   id<OIDExternalUserAgentSession> _currentAuthorizationFlow;
   id<OIDExternalUserAgentSession> _currentAuthorizationFlow;
+   // Flag to indicate that the auth flow is restarting.
+   BOOL _restarting;
 }
 }
 
 
 #pragma mark - Public methods
 #pragma mark - Public methods
@@ -446,6 +448,12 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
          presentingViewController:options.presentingViewController
          presentingViewController:options.presentingViewController
                          callback:^(OIDAuthorizationResponse *_Nullable authorizationResponse,
                          callback:^(OIDAuthorizationResponse *_Nullable authorizationResponse,
                                     NSError *_Nullable error) {
                                     NSError *_Nullable error) {
+    if (_restarting) {
+      // The auth flow is restarting, so the work here would be performed in the next round.
+      _restarting = NO;
+      return;
+    }
+
     GIDAuthFlow *authFlow = [[GIDAuthFlow alloc] init];
     GIDAuthFlow *authFlow = [[GIDAuthFlow alloc] init];
     authFlow.emmSupport = emmSupport;
     authFlow.emmSupport = emmSupport;
 
 
@@ -726,8 +734,10 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
   if (!_currentAuthorizationFlow) {
   if (!_currentAuthorizationFlow) {
     return NO;
     return NO;
   }
   }
+  _restarting = YES;
   [_currentAuthorizationFlow cancel];
   [_currentAuthorizationFlow cancel];
   _currentAuthorizationFlow = nil;
   _currentAuthorizationFlow = nil;
+  _restarting = NO;
   NSDictionary<NSString *, NSString *> *extraParameters = @{ kEMMRestartAuthParameter : @"1" };
   NSDictionary<NSString *, NSString *> *extraParameters = @{ kEMMRestartAuthParameter : @"1" };
   // In iOS 13 the presentation of ASWebAuthenticationSession needs an anchor window,
   // In iOS 13 the presentation of ASWebAuthenticationSession needs an anchor window,
   // so we need to wait until the previous presentation is completely gone to ensure the right
   // so we need to wait until the previous presentation is completely gone to ensure the right