Peter Andrews 4 лет назад
Родитель
Сommit
e9f126f39f
2 измененных файлов с 20 добавлено и 15 удалено
  1. 8 15
      GoogleSignIn/Sources/GIDSignIn.m
  2. 12 0
      GoogleSignIn/Tests/Unit/GIDSignInTest.m

+ 8 - 15
GoogleSignIn/Sources/GIDSignIn.m

@@ -208,7 +208,14 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
 }
 
 - (void)signOut {
-  [self signOutWithUser:_currentUser];
+  // Clear the current user if there is one.
+  if (_currentUser) {
+    [self willChangeValueForKey:NSStringFromSelector(@selector(currentUser))];
+    _currentUser = nil;
+    [self didChangeValueForKey:NSStringFromSelector(@selector(currentUser))];
+  }
+  // Remove all state from the keychain.
+  [self removeAllKeychainEntries];
 }
 
 - (void)disconnectWithCallback:(GIDSignInCallback)callback {
@@ -751,13 +758,6 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
   [GTMAppAuthFetcherAuthorization removeAuthorizationFromKeychainForName:kGTMAppAuthKeychainName];
 }
 
-// Clears the saved authentication object and other user information.
-- (void)clearAuthentication {
-  [self willChangeValueForKey:NSStringFromSelector(@selector(currentUser))];
-  _currentUser = nil;
-  [self didChangeValueForKey:NSStringFromSelector(@selector(currentUser))];
-}
-
 // Adds basic profile scopes to |scopes| if |shouldFetchBasicProfile| is set.
 - (NSArray *)adjustedScopes {
   NSArray<NSString *> *adjustedScopes = _scopes;
@@ -772,13 +772,6 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
   return [NSURL URLWithString:[NSString stringWithFormat:@"%@:%@", scheme, kBrowserCallbackPath]];
 }
 
-- (void)signOutWithUser:(GIDGoogleUser *)user {
-  // TODO(petea): Respond to user parameter.
-  // TODO(petea): Mark user as signed out rather than removing auth from keychain.
-  [self clearAuthentication];
-  [self removeAllKeychainEntries];
-}
-
 - (BOOL)saveAuthState:(OIDAuthState *)authState {
   GTMAppAuthFetcherAuthorization *authorization =
       [[GTMAppAuthFetcherAuthorization alloc] initWithAuthState:authState];

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

@@ -573,6 +573,18 @@ static void *kTestObserverContext = &kTestObserverContext;
 }
 
 - (void)testSignOut {
+  // Sign in a user so that we can then sign them out.
+  [self OAuthLoginWithOptions:nil
+                    authError:nil
+                   tokenError:nil
+      emmPasscodeInfoRequired:NO
+                keychainError:NO
+               restoredSignIn:YES
+               oldAccessToken:NO
+                  modalCancel:NO];
+
+  XCTAssertNotNil(_signIn.currentUser);
+
   [_signIn signOut];
   XCTAssertNil(_signIn.currentUser, @"should not have a current user");
   XCTAssertTrue(_keychainRemoved, @"should remove keychain");