@@ -629,7 +629,7 @@ - (void)processAuthorizationResponse:(OIDAuthorizationResponse *)authorizationRe
629629 authFlow.authState = [[OIDAuthState alloc ]
630630 initWithAuthorizationResponse: authorizationResponse];
631631 // perform auth code exchange
632- [self maybeFetchToken: authFlow];
632+ [self maybeFetchToken: authFlow fallback: nil ];
633633 } else {
634634 // There was a failure, convert to appropriate error code.
635635 NSString *errorString;
@@ -701,14 +701,17 @@ - (void)authenticateWithOptions:(GIDSignInInternalOptions *)options {
701701 // Complete the auth flow using saved auth in keychain.
702702 GIDAuthFlow *authFlow = [[GIDAuthFlow alloc ] init ];
703703 authFlow.authState = authState;
704- [self maybeFetchToken: authFlow];
704+ [self maybeFetchToken: authFlow fallback: options.interactive ? ^() {
705+ [self authenticateInteractivelyWithOptions: options];
706+ } : nil ];
705707 [self addDecodeIdTokenCallback: authFlow];
706708 [self addSaveAuthCallback: authFlow];
707709 [self addCompletionCallback: authFlow];
708710}
709711
710- // Fetches the access token if necessary as part of the auth flow.
711- - (void )maybeFetchToken : (GIDAuthFlow *)authFlow {
712+ // Fetches the access token if necessary as part of the auth flow. If |fallback|
713+ // is provided, call it instead of continuing the auth flow in case of error.
714+ - (void )maybeFetchToken : (GIDAuthFlow *)authFlow fallback : (nullable void (^)(void ))fallback {
712715 OIDAuthState *authState = authFlow.authState ;
713716 // Do nothing if we have an auth flow error or a restored access token that isn't near expiration.
714717 if (authFlow.error ||
@@ -755,6 +758,14 @@ - (void)maybeFetchToken:(GIDAuthFlow *)authFlow {
755758 [authState updateWithTokenResponse: tokenResponse error: error];
756759 authFlow.error = error;
757760
761+ if (!tokenResponse.accessToken || error) {
762+ if (fallback) {
763+ [authFlow reset ];
764+ fallback ();
765+ return ;
766+ }
767+ }
768+
758769#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
759770 if (authFlow.emmSupport ) {
760771 [GIDAuthentication handleTokenFetchEMMError: error completion: ^(NSError *error) {
0 commit comments