Pārlūkot izejas kodu

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 gadi atpakaļ
vecāks
revīzija
3bf36c1748
1 mainītis faili ar 10 papildinājumiem un 0 dzēšanām
  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;
   // AppAuth external user-agent session state.
   id<OIDExternalUserAgentSession> _currentAuthorizationFlow;
+   // Flag to indicate that the auth flow is restarting.
+   BOOL _restarting;
 }
 
 #pragma mark - Public methods
@@ -446,6 +448,12 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
          presentingViewController:options.presentingViewController
                          callback:^(OIDAuthorizationResponse *_Nullable authorizationResponse,
                                     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];
     authFlow.emmSupport = emmSupport;
 
@@ -726,8 +734,10 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
   if (!_currentAuthorizationFlow) {
     return NO;
   }
+  _restarting = YES;
   [_currentAuthorizationFlow cancel];
   _currentAuthorizationFlow = nil;
+  _restarting = NO;
   NSDictionary<NSString *, NSString *> *extraParameters = @{ kEMMRestartAuthParameter : @"1" };
   // 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