Bladeren bron

Replace GIDSignInCallback

Replace GIDSignInCallback with block
void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error)
pinlu 3 jaren geleden
bovenliggende
commit
174e6b815a

+ 18 - 13
GoogleSignIn/Sources/GIDSignIn.m

@@ -34,6 +34,7 @@
 #import "GoogleSignIn/Sources/GIDAuthentication_Private.h"
 #import "GoogleSignIn/Sources/GIDGoogleUser_Private.h"
 #import "GoogleSignIn/Sources/GIDProfileData_Private.h"
+#import "GoogleSignIn/Sources/GIDUserAuth_Private.h"
 
 #ifdef SWIFT_PACKAGE
 @import AppAuth;
@@ -187,7 +188,7 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
   return [authState isAuthorized];
 }
 
-- (void)restorePreviousSignInWithCallback:(nullable GIDSignInCallback)callback {
+- (void)restorePreviousSignInWithCallback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback {
   [self signInWithOptions:[GIDSignInInternalOptions silentOptionsWithCallback:callback]];
 }
 
@@ -217,7 +218,7 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
 - (void)signInWithConfiguration:(GIDConfiguration *)configuration
        presentingViewController:(UIViewController *)presentingViewController
                            hint:(nullable NSString *)hint
-                       callback:(nullable GIDSignInCallback)callback {
+                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback {
   GIDSignInInternalOptions *options =
       [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
                                        presentingViewController:presentingViewController
@@ -231,7 +232,7 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
        presentingViewController:(UIViewController *)presentingViewController
                            hint:(nullable NSString *)hint
                additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
-                       callback:(nullable GIDSignInCallback)callback {
+                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback {
   GIDSignInInternalOptions *options =
     [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
                                      presentingViewController:presentingViewController
@@ -244,7 +245,7 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
 
 - (void)signInWithConfiguration:(GIDConfiguration *)configuration
        presentingViewController:(UIViewController *)presentingViewController
-                       callback:(nullable GIDSignInCallback)callback {
+                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback {
   [self signInWithConfiguration:configuration
        presentingViewController:presentingViewController
                            hint:nil
@@ -253,7 +254,7 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
 
 - (void)addScopes:(NSArray<NSString *> *)scopes
     presentingViewController:(UIViewController *)presentingViewController
-                    callback:(nullable GIDSignInCallback)callback {
+                    callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback {
   // A currentUser must be available in order to complete this flow.
   if (!self.currentUser) {
     // No currentUser is set, notify callback of failure.
@@ -310,7 +311,7 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
 - (void)signInWithConfiguration:(GIDConfiguration *)configuration
                presentingWindow:(NSWindow *)presentingWindow
                            hint:(nullable NSString *)hint
-                       callback:(nullable GIDSignInCallback)callback {
+                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback {
   GIDSignInInternalOptions *options =
       [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
                                                presentingWindow:presentingWindow
@@ -322,7 +323,7 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
 
 - (void)signInWithConfiguration:(GIDConfiguration *)configuration
                presentingWindow:(NSWindow *)presentingWindow
-                       callback:(nullable GIDSignInCallback)callback {
+                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback {
   [self signInWithConfiguration:configuration
                presentingWindow:presentingWindow
                            hint:nil
@@ -333,7 +334,7 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
                presentingWindow:(NSWindow *)presentingWindow
                            hint:(nullable NSString *)hint
                additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
-                       callback:(nullable GIDSignInCallback)callback {
+                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback {
   GIDSignInInternalOptions *options =
     [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
                                              presentingWindow:presentingWindow
@@ -346,7 +347,7 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
 
 - (void)addScopes:(NSArray<NSString *> *)scopes
             presentingWindow:(NSWindow *)presentingWindow
-                    callback:(nullable GIDSignInCallback)callback {
+                    callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback {
   // A currentUser must be available in order to complete this flow.
   if (!self.currentUser) {
     // No currentUser is set, notify callback of failure.
@@ -541,7 +542,8 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
         if (options.callback) {
           self->_currentOptions = nil;
           dispatch_async(dispatch_get_main_queue(), ^{
-            options.callback(self->_currentUser, nil);
+            GIDUserAuth *userAuth = [[GIDUserAuth alloc]initWithGoogleUser:self->_currentUser serverAuthCode:nil];
+            options.callback(userAuth, nil);
           });
         }
       }
@@ -601,7 +603,7 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
   _currentAuthorizationFlow = [OIDAuthorizationService
       presentAuthorizationRequest:request
          presentingViewController:options.presentingViewController
-                        callback:^(OIDAuthorizationResponse *_Nullable authorizationResponse,
+                         callback:^(OIDAuthorizationResponse *_Nullable authorizationResponse,
                                    NSError *_Nullable error) {
     [self processAuthorizationResponse:authorizationResponse
                                  error:error
@@ -882,10 +884,13 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
   [authFlow addCallback:^() {
     GIDAuthFlow *handlerAuthFlow = weakAuthFlow;
     if (self->_currentOptions.callback) {
-      GIDSignInCallback callback = self->_currentOptions.callback;
+      void (^callback)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error) = self->_currentOptions.callback;
       self->_currentOptions = nil;
       dispatch_async(dispatch_get_main_queue(), ^{
-        callback(self->_currentUser, handlerAuthFlow.error);
+        OIDAuthState *authState = handlerAuthFlow.authState;
+        NSString * _Nullable serverAuthCode = [authState.lastTokenResponse.additionalParameters[@"server_code"] copy];
+        GIDUserAuth *  userAuth = [[GIDUserAuth alloc]initWithGoogleUser:self->_currentUser serverAuthCode:serverAuthCode];
+        callback(userAuth, handlerAuthFlow.error);
       });
     }
   }];

+ 7 - 6
GoogleSignIn/Sources/GIDSignInInternalOptions.h

@@ -25,6 +25,7 @@
 #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h"
 
 @class GIDConfiguration;
+@class GIDUserAuth;
 
 NS_ASSUME_NONNULL_BEGIN
 
@@ -55,7 +56,7 @@ NS_ASSUME_NONNULL_BEGIN
 #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
 
 /// The callback block to be called at the completion of the flow.
-@property(nonatomic, readonly, nullable) GIDSignInCallback callback;
+@property(nonatomic, readonly, nullable) void (^callback)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error);
 
 /// The scopes to be used during the flow.
 @property(nonatomic, copy, nullable) NSArray<NSString *> *scopes;
@@ -69,32 +70,32 @@ NS_ASSUME_NONNULL_BEGIN
                        presentingViewController:(nullable UIViewController *)presentingViewController
                                       loginHint:(nullable NSString *)loginHint
                                   addScopesFlow:(BOOL)addScopesFlow
-                                       callback:(nullable GIDSignInCallback)callback;
+                                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback;
 
 + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
                        presentingViewController:(nullable UIViewController *)presentingViewController
                                       loginHint:(nullable NSString *)loginHint
                                   addScopesFlow:(BOOL)addScopesFlow
                                          scopes:(nullable NSArray *)scopes
-                                       callback:(nullable GIDSignInCallback)callback;
+                                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback;
 
 #elif TARGET_OS_OSX
 + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
                                presentingWindow:(nullable NSWindow *)presentingWindow
                                       loginHint:(nullable NSString *)loginHint
                                   addScopesFlow:(BOOL)addScopesFlow
-                                       callback:(nullable GIDSignInCallback)callback;
+                                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback;
 
 + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
                                presentingWindow:(nullable NSWindow *)presentingWindow
                                       loginHint:(nullable NSString *)loginHint
                                   addScopesFlow:(BOOL)addScopesFlow
                                          scopes:(nullable NSArray *)scopes
-                                       callback:(nullable GIDSignInCallback)callback;
+                                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback;
 #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
 
 /// Creates the options to sign in silently.
-+ (instancetype)silentOptionsWithCallback:(GIDSignInCallback)callback;
++ (instancetype)silentOptionsWithCallback:(void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback;
 
 /// Creates options with the same values as the receiver, except for the "extra parameters", and
 /// continuation flag, which are replaced by the arguments passed to this method.

+ 5 - 5
GoogleSignIn/Sources/GIDSignInInternalOptions.m

@@ -31,14 +31,14 @@ NS_ASSUME_NONNULL_BEGIN
                                       loginHint:(nullable NSString *)loginHint
                                   addScopesFlow:(BOOL)addScopesFlow
                                          scopes:(nullable NSArray *)scopes
-                                       callback:(nullable GIDSignInCallback)callback {
+                                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback {
 #elif TARGET_OS_OSX
 + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
                                presentingWindow:(nullable NSWindow *)presentingWindow
                                       loginHint:(nullable NSString *)loginHint
                                   addScopesFlow:(BOOL)addScopesFlow
                                          scopes:(nullable NSArray *)scopes
-                                       callback:(nullable GIDSignInCallback)callback {
+                                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback {
 #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
   
   GIDSignInInternalOptions *options = [[GIDSignInInternalOptions alloc] init];
@@ -64,13 +64,13 @@ NS_ASSUME_NONNULL_BEGIN
                        presentingViewController:(nullable UIViewController *)presentingViewController
                                       loginHint:(nullable NSString *)loginHint
                                   addScopesFlow:(BOOL)addScopesFlow
-                                       callback:(nullable GIDSignInCallback)callback {
+                                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback {
 #elif TARGET_OS_OSX
 + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
                                presentingWindow:(nullable NSWindow *)presentingWindow
                                       loginHint:(nullable NSString *)loginHint
                                   addScopesFlow:(BOOL)addScopesFlow
-                                       callback:(nullable GIDSignInCallback)callback {
+                                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback {
 #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
     GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:configuration
 #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
@@ -85,7 +85,7 @@ NS_ASSUME_NONNULL_BEGIN
   return options;
 }
 
-+ (instancetype)silentOptionsWithCallback:(GIDSignInCallback)callback {
++ (instancetype)silentOptionsWithCallback:(void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback {
   GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:nil
 #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
                                                    presentingViewController:nil

+ 10 - 13
GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h

@@ -25,6 +25,7 @@
 
 @class GIDConfiguration;
 @class GIDGoogleUser;
+@class GIDUserAuth;
 
 NS_ASSUME_NONNULL_BEGIN
 
@@ -50,10 +51,6 @@ typedef NS_ERROR_ENUM(kGIDSignInErrorDomain, GIDSignInErrorCode) {
   kGIDSignInErrorCodeScopesAlreadyGranted = -8,
 };
 
-/// Represents a callback block that takes a `GIDGoogleUser` on success or an error if the operation
-/// was unsuccessful.
-typedef void (^GIDSignInCallback)(GIDGoogleUser *_Nullable user, NSError *_Nullable error);
-
 /// Represents a callback block that takes an error if the operation was unsuccessful.
 typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
 
@@ -93,7 +90,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
 ///
 /// @param callback The `GIDSignInCallback` block that is called on completion.  This block will be
 ///     called asynchronously on the main queue.
-- (void)restorePreviousSignInWithCallback:(nullable GIDSignInCallback)callback;
+- (void)restorePreviousSignInWithCallback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback;
 
 /// Marks current user as being in the signed out state.
 - (void)signOut;
@@ -121,7 +118,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
 ///     called asynchronously on the main queue.
 - (void)signInWithConfiguration:(GIDConfiguration *)configuration
        presentingViewController:(UIViewController *)presentingViewController
-                       callback:(nullable GIDSignInCallback)callback
+                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback
     NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions.");
 
 /// Starts an interactive sign-in flow  on iOS using the provided configuration and a login hint.
@@ -142,7 +139,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
 - (void)signInWithConfiguration:(GIDConfiguration *)configuration
        presentingViewController:(UIViewController *)presentingViewController
                            hint:(nullable NSString *)hint
-                       callback:(nullable GIDSignInCallback)callback
+                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback
     NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions.");
 
 /// Starts an interactive sign-in flow on iOS using the provided configuration and a login hint.
@@ -165,7 +162,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
        presentingViewController:(UIViewController *)presentingViewController
                            hint:(nullable NSString *)hint
                additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
-                       callback:(nullable GIDSignInCallback)callback;
+                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback;
 
 /// Starts an interactive consent flow on iOS to add scopes to the current user's grants.
 ///
@@ -180,7 +177,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
 ///     called asynchronously on the main queue.
 - (void)addScopes:(NSArray<NSString *> *)scopes
     presentingViewController:(UIViewController *)presentingViewController
-                    callback:(nullable GIDSignInCallback)callback
+                    callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback
     NS_EXTENSION_UNAVAILABLE("The add scopes flow is not supported in App Extensions."); 
 
 #elif TARGET_OS_OSX
@@ -197,7 +194,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
 ///     called asynchronously on the main queue.
 - (void)signInWithConfiguration:(GIDConfiguration *)configuration
                presentingWindow:(NSWindow *)presentingWindow
-                       callback:(nullable GIDSignInCallback)callback;
+                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback;
 
 /// Starts an interactive sign-in flow on macOS using the provided configuration and a login hint.
 ///
@@ -215,7 +212,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
 - (void)signInWithConfiguration:(GIDConfiguration *)configuration
                presentingWindow:(NSWindow *)presentingWindow
                            hint:(nullable NSString *)hint
-                       callback:(nullable GIDSignInCallback)callback;
+                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback;
 
 /// Starts an interactive sign-in flow on macOS using the provided configuration and a login hint.
 ///
@@ -236,7 +233,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
                presentingWindow:(NSWindow *)presentingWindow
                            hint:(nullable NSString *)hint
                additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
-                       callback:(nullable GIDSignInCallback)callback;
+                       callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback;
 
 /// Starts an interactive consent flow on macOS to add scopes to the current user's grants.
 ///
@@ -249,7 +246,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
 ///     called asynchronously on the main queue.
 - (void)addScopes:(NSArray<NSString *> *)scopes
        presentingWindow:(NSWindow *)presentingWindow
-               callback:(nullable GIDSignInCallback)callback;
+               callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error))callback;
 
 #endif
 

+ 1 - 0
GoogleSignIn/Sources/Public/GoogleSignIn/GoogleSignIn.h

@@ -20,6 +20,7 @@
 #import "GIDGoogleUser.h"
 #import "GIDProfileData.h"
 #import "GIDSignIn.h"
+#import "GIDUserAuth.h"
 #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
 #import "GIDSignInButton.h"
 #endif

+ 2 - 2
GoogleSignIn/Tests/Unit/GIDSignInInternalOptionsTest.m

@@ -37,7 +37,7 @@
   id presentingWindow = OCMStrictClassMock([NSWindow class]);
 #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
   NSString *loginHint = @"login_hint";
-  GIDSignInCallback callback = ^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) {};
+  void (^callback)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error) = ^(GIDUserAuth *_Nullable userAuth, NSError * _Nullable error) {};
   
   GIDSignInInternalOptions *options =
       [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
@@ -63,7 +63,7 @@
 }
 
 - (void)testSilentOptions {
-  GIDSignInCallback callback = ^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) {};
+  void (^callback)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error) = ^(GIDUserAuth *_Nullable userAuth, NSError * _Nullable error) {};
   GIDSignInInternalOptions *options = [GIDSignInInternalOptions silentOptionsWithCallback:callback];
   XCTAssertFalse(options.interactive);
   XCTAssertFalse(options.continuation);

+ 28 - 13
GoogleSignIn/Tests/Unit/GIDSignInTest.m

@@ -241,7 +241,7 @@ static void *kTestObserverContext = &kTestObserverContext;
   NSString *_hint;
 
   // The callback to be used when testing |GIDSignIn|.
-  GIDSignInCallback _callback;
+  void (^_callback)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error);
 
   // The saved authorization request.
   OIDAuthorizationRequest *_savedAuthorizationRequest;
@@ -346,10 +346,10 @@ static void *kTestObserverContext = &kTestObserverContext;
   _hint = nil;
 
   __weak GIDSignInTest *weakSelf = self;
-  _callback = ^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) {
+  _callback = ^(GIDUserAuth *_Nullable userAuth, NSError * _Nullable error) {
     GIDSignInTest *strongSelf = weakSelf;
-    if (!user) {
-      XCTAssertNotNil(error, @"should have an error if user is nil");
+    if (!userAuth) {
+      XCTAssertNotNil(error, @"should have an error if the userAuth is nil");
     }
     XCTAssertFalse(strongSelf->_callbackCalled, @"callback already called");
     strongSelf->_callbackCalled = YES;
@@ -456,7 +456,7 @@ static void *kTestObserverContext = &kTestObserverContext;
 
   XCTestExpectation *expectation = [self expectationWithDescription:@"Callback should be called."];
 
-  [_signIn restorePreviousSignInWithCallback:^(GIDGoogleUser * _Nullable user,
+  [_signIn restorePreviousSignInWithCallback:^(GIDUserAuth *_Nullable userAuth,
                                                NSError * _Nullable error) {
     [expectation fulfill];
     XCTAssertNotNil(error, @"error should not have been nil");
@@ -1073,6 +1073,7 @@ static void *kTestObserverContext = &kTestObserverContext;
   NSError *handledError = [NSError errorWithDomain:kGIDSignInErrorDomain
                                               code:kGIDSignInErrorCodeEMM
                                           userInfo:emmError.userInfo];
+  
   completion(handledError);
 
   [self waitForExpectationsWithTimeout:1 handler:nil];
@@ -1220,10 +1221,16 @@ static void *kTestObserverContext = &kTestObserverContext;
     }
   } else {
     XCTestExpectation *expectation = [self expectationWithDescription:@"Callback called"];
-    GIDSignInCallback callback = ^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) {
+    void (^callback)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error) =
+    ^(GIDUserAuth *_Nullable userAuth, NSError * _Nullable error) {
       [expectation fulfill];
-      if (!user) {
-        XCTAssertNotNil(error, @"should have an error if user is nil");
+      if (userAuth) {
+        BOOL hasError = authError || modalCancel || tokenError;
+        if (!hasError) {
+          XCTAssertEqualObjects(userAuth.serverAuthCode, kServerAuthCode);
+        }
+      } else {
+        XCTAssertNotNil(error, @"should have an error if the userAuth is nil");
       }
       XCTAssertFalse(self->_callbackCalled, @"callback already called");
       self->_callbackCalled = YES;
@@ -1286,7 +1293,7 @@ static void *kTestObserverContext = &kTestObserverContext;
       [[[_authState expect] andReturn:authResponse] lastAuthorizationResponse];
       [[[_authState expect] andReturn:authResponse] lastAuthorizationResponse];
     }
-
+    
     // Simulate auth endpoint response
     if (modalCancel) {
       NSError *error = [NSError errorWithDomain:OIDGeneralErrorDomain
@@ -1305,7 +1312,7 @@ static void *kTestObserverContext = &kTestObserverContext;
 
   if (restoredSignIn && oldAccessToken) {
     XCTestExpectation *expectation = [self expectationWithDescription:@"Callback should be called"];
-    [_signIn restorePreviousSignInWithCallback:^(GIDGoogleUser * _Nullable user,
+    [_signIn restorePreviousSignInWithCallback:^(GIDUserAuth *_Nullable userAuth,
                                                  NSError * _Nullable error) {
       [expectation fulfill];
       XCTAssertNil(error, @"should have no error");
@@ -1319,6 +1326,9 @@ static void *kTestObserverContext = &kTestObserverContext;
     // OIDTokenCallback
     if (tokenError) {
       [[_authState expect] updateWithTokenResponse:nil error:tokenError];
+      
+      // CompletionCallback
+      [[[_authState expect] andReturn:nil] lastTokenResponse];
     } else {
       [[_authState expect] updateWithTokenResponse:[OCMArg any] error:nil];
     }
@@ -1348,10 +1358,13 @@ static void *kTestObserverContext = &kTestObserverContext;
                                                     profileData:SAVE_TO_ARG_BLOCK(profileData)];
     }
   }
+  
+  // CompletionCallback - mock server auth code parsing
+  [[[_authState expect] andReturn:tokenResponse] lastTokenResponse];
 
   if (restoredSignIn && !oldAccessToken) {
     XCTestExpectation *expectation = [self expectationWithDescription:@"Callback should be called"];
-    [_signIn restorePreviousSignInWithCallback:^(GIDGoogleUser * _Nullable user,
+    [_signIn restorePreviousSignInWithCallback:^(GIDUserAuth *_Nullable userAuth,
                                                  NSError * _Nullable error) {
       [expectation fulfill];
       XCTAssertNil(error, @"should have no error");
@@ -1361,11 +1374,13 @@ static void *kTestObserverContext = &kTestObserverContext;
     _savedTokenCallback(tokenResponse, nil);
   }
 
-  [_authState verify];
   if (keychainError) {
     return;
   }
   [self waitForExpectationsWithTimeout:1 handler:nil];
+  
+  [_authState verify];
+  
   XCTAssertTrue(_keychainSaved, @"should save to keychain");
   XCTAssertNotNil(authState);
   // Check fat ID token decoding
@@ -1390,7 +1405,7 @@ static void *kTestObserverContext = &kTestObserverContext;
 
   XCTestExpectation *expectation = [self expectationWithDescription:@"Callback should be called"];
 
-  [_signIn restorePreviousSignInWithCallback:^(GIDGoogleUser * _Nullable user,
+  [_signIn restorePreviousSignInWithCallback:^(GIDUserAuth *_Nullable userAuth,
                                                NSError * _Nullable error) {
     [expectation fulfill];
     XCTAssertNil(error, @"should have no error");