Explorar el Código

Add GIDDisconnectCallback.

Peter Andrews hace 4 años
padre
commit
3d31d016bc

+ 4 - 4
GoogleSignIn/Sources/GIDSignIn.m

@@ -218,7 +218,7 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
   [self removeAllKeychainEntries];
 }
 
-- (void)disconnectWithCallback:(GIDSignInCallback)callback {
+- (void)disconnectWithCallback:(GIDDisconnectCallback)callback {
   GIDGoogleUser *user = _currentUser;
   OIDAuthState *authState = user.authentication.authState;
   if (!authState) {
@@ -235,7 +235,7 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
   if (!token) {
     [self signOut];
     // Nothing to do here, consider the operation successful.
-    callback(user, nil);
+    callback(nil);
     return;
   }
   NSString *revokeURLString = [NSString stringWithFormat:kRevokeTokenURLTemplate,
@@ -253,10 +253,10 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
     // Revoking an already revoked token seems always successful, which saves the trouble here for
     // us.
     if (error) {
-      callback(nil, error);
+      callback(error);
     } else {
       [self signOut];
-      callback(user, nil);
+      callback(nil);
     }
   }];
 }

+ 6 - 3
GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h

@@ -40,10 +40,13 @@ typedef NS_ENUM(NSInteger, GIDSignInErrorCode) {
   kGIDSignInErrorCodeEMM = -6,
 };
 
-/// Represents a callback block that takes a `GIDGoogleUser` or an error if the operation was
-/// unsuccessful.
+/// 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);
+
 /// A protocol implemented by the delegate of `GIDSignIn` to receive a refresh token or an error.
 @protocol GIDSignInDelegate <NSObject>
 
@@ -169,7 +172,7 @@ typedef void (^GIDSignInCallback)(GIDGoogleUser *_Nullable user, NSError *_Nulla
 /// succeeds, the OAuth 2.0 token is also removed from keychain.
 ///
 /// @param callback The `GIDSignInCallback` block that is called on completion.
-- (void)disconnectWithCallback:(GIDSignInCallback)callback;
+- (void)disconnectWithCallback:(GIDDisconnectCallback)callback;
 
 @end
 

+ 12 - 12
GoogleSignIn/Tests/Unit/GIDSignInTest.m

@@ -612,9 +612,9 @@ static void *kTestObserverContext = &kTestObserverContext;
   [[[_tokenResponse expect] andReturn:kAccessToken] accessToken];
   [[[_authorization expect] andReturn:_fetcherService] fetcherService];
   XCTestExpectation *expectation =
-      [self expectationWithDescription:@"Callback called with nil user and nil error"];
-  [_signIn disconnectWithCallback:^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) {
-    if (user == nil && error == nil) {
+      [self expectationWithDescription:@"Callback called with nil error"];
+  [_signIn disconnectWithCallback:^(NSError * _Nullable error) {
+    if (error == nil) {
       [expectation fulfill];
     }
   }];
@@ -633,9 +633,9 @@ static void *kTestObserverContext = &kTestObserverContext;
   [[[_tokenResponse expect] andReturn:kRefreshToken] refreshToken];
   [[[_authorization expect] andReturn:_fetcherService] fetcherService];
   XCTestExpectation *expectation =
-      [self expectationWithDescription:@"Callback called with nil user and nil error"];
-  [_signIn disconnectWithCallback:^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) {
-    if (user == nil && error == nil) {
+      [self expectationWithDescription:@"Callback called with nil error"];
+  [_signIn disconnectWithCallback:^(NSError * _Nullable error) {
+    if (error == nil) {
       [expectation fulfill];
     }
   }];
@@ -652,9 +652,9 @@ static void *kTestObserverContext = &kTestObserverContext;
   [[[_tokenResponse expect] andReturn:kAccessToken] accessToken];
   [[[_authorization expect] andReturn:_fetcherService] fetcherService];
   XCTestExpectation *expectation =
-      [self expectationWithDescription:@"Callback called with nil user and an error"];
-  [_signIn disconnectWithCallback:^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) {
-    if (user == nil && error != nil) {
+      [self expectationWithDescription:@"Callback called with an error"];
+  [_signIn disconnectWithCallback:^(NSError * _Nullable error) {
+    if (error != nil) {
       [expectation fulfill];
     }
   }];
@@ -677,9 +677,9 @@ static void *kTestObserverContext = &kTestObserverContext;
   [[[_authState expect] andReturn:_tokenResponse] lastTokenResponse];
   [[[_tokenResponse expect] andReturn:nil] refreshToken];
   XCTestExpectation *expectation =
-      [self expectationWithDescription:@"Callback called with nil user and nil error"];
-  [_signIn disconnectWithCallback:^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) {
-    if (user == nil && error == nil) {
+      [self expectationWithDescription:@"Callback called with nil error"];
+  [_signIn disconnectWithCallback:^(NSError * _Nullable error) {
+    if (error == nil) {
       [expectation fulfill];
     }
   }];

+ 1 - 2
Sample/Source/SignInViewController.m

@@ -283,8 +283,7 @@ static NSString *const kCredentialsButtonAccessibilityIdentifier = @"Credentials
 }
 
 - (IBAction)disconnect:(id)sender {
-  [[GIDSignIn sharedInstance] disconnectWithCallback:^(GIDGoogleUser * _Nullable user,
-                                                       NSError * _Nullable error) {
+  [[GIDSignIn sharedInstance] disconnectWithCallback:^(NSError * _Nullable error) {
     if (error) {
       self->_signInAuthStatus.text = [NSString stringWithFormat:@"Status: Failed to disconnect: %@",
                                       error];