Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions GoogleSignIn/Sources/GIDSignIn.m
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ - (BOOL)restorePreviousSignInNoRefresh {
GIDProfileData *profileData = [self profileDataWithIDToken:idToken];

GIDGoogleUser *user = [[GIDGoogleUser alloc] initWithAuthState:authState profileData:profileData];
[self setCurrentUserWithKVO:user];
self.currentUser = user;
return YES;
}

Expand Down Expand Up @@ -401,9 +401,7 @@ - (void)addScopes:(NSArray<NSString *> *)scopes
- (void)signOut {
// Clear the current user if there is one.
if (_currentUser) {
[self willChangeValueForKey:NSStringFromSelector(@selector(currentUser))];
_currentUser = nil;
[self didChangeValueForKey:NSStringFromSelector(@selector(currentUser))];
self.currentUser = nil;
}
// Remove all state from the keychain.
[self removeAllKeychainEntries];
Expand Down Expand Up @@ -803,7 +801,7 @@ - (void)addSaveAuthCallback:(GIDAuthFlow *)authFlow {
} else {
GIDGoogleUser *user = [[GIDGoogleUser alloc] initWithAuthState:authState
profileData:handlerAuthFlow.profileData];
[self setCurrentUserWithKVO:user];
self.currentUser = user;
}
}
}];
Expand Down Expand Up @@ -935,17 +933,6 @@ - (BOOL)handleDevicePolicyAppURL:(NSURL *)url {
return YES;
}

#pragma mark - Key-Value Observing

// Override |NSObject(NSKeyValueObservingCustomization)| method in order to provide custom KVO
// notifications for the |currentUser| property.
+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key {
if ([key isEqual:NSStringFromSelector(@selector(currentUser))]) {
return NO;
}
return [super automaticallyNotifiesObserversForKey:key];
}

#pragma mark - Helpers

- (NSError *)errorWithString:(NSString *)errorString code:(GIDSignInErrorCode)code {
Expand Down Expand Up @@ -1035,13 +1022,6 @@ - (GIDProfileData *)profileDataWithIDToken:(OIDIDToken *)idToken {
imageURL:[NSURL URLWithString:idToken.claims[kBasicProfilePictureKey]]];
}

// Set currentUser making appropriate KVO calls.
- (void)setCurrentUserWithKVO:(GIDGoogleUser *_Nullable)user {
[self willChangeValueForKey:NSStringFromSelector(@selector(currentUser))];
_currentUser = user;
[self didChangeValueForKey:NSStringFromSelector(@selector(currentUser))];
}

// Try to retrieve a configuration value from an |NSBundle|'s Info.plist for a given key.
+ (nullable NSString *)configValueFromBundle:(NSBundle *)bundle forKey:(NSString *)key {
NSString *value;
Expand Down
3 changes: 3 additions & 0 deletions GoogleSignIn/Sources/GIDSignIn_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ NS_ASSUME_NONNULL_BEGIN
// Private |GIDSignIn| methods that are used internally in this SDK and other Google SDKs.
@interface GIDSignIn ()

// Redeclare |currentUser| as readwrite for internal use.
@property(nonatomic, readwrite, nullable) GIDGoogleUser *currentUser;

// Private initializer for |GIDSignIn|.
- (instancetype)initPrivate;

Expand Down
30 changes: 0 additions & 30 deletions GoogleSignIn/Tests/Unit/GIDSignInTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@
static NSString *const kGrantedScope = @"grantedScope";
static NSString *const kNewScope = @"newScope";

/// Unique pointer value for KVO tests.
static void *kTestObserverContext = &kTestObserverContext;

#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
// This category is used to allow the test to swizzle a private method.
@interface UIViewController (Testing)
Expand Down Expand Up @@ -263,9 +260,6 @@ @interface GIDSignInTest : XCTestCase {
// The saved token request callback.
OIDTokenCallback _savedTokenCallback;

// Set of all |GIDSignIn| key paths which were observed to change.
NSMutableSet *_changedKeyPaths;

// Status returned by saveAuthorization:toKeychainForName:
BOOL _saveAuthorizationReturnValue;
}
Expand All @@ -286,7 +280,6 @@ - (void)setUp {
_completionCalled = NO;
_keychainSaved = NO;
_keychainRemoved = NO;
_changedKeyPaths = [[NSMutableSet alloc] init];

// Mocks
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
Expand Down Expand Up @@ -354,11 +347,6 @@ - (void)setUp {
strongSelf->_completionCalled = YES;
strongSelf->_authError = error;
};

[_signIn addObserver:self
forKeyPath:NSStringFromSelector(@selector(currentUser))
options:0
context:kTestObserverContext];
}

- (void)tearDown {
Expand All @@ -379,10 +367,6 @@ - (void)tearDown {

[_fakeMainBundle stopFaking];
[super tearDown];

[_signIn removeObserver:self
forKeyPath:NSStringFromSelector(@selector(currentUser))
context:kTestObserverContext];
}

#pragma mark - Tests
Expand Down Expand Up @@ -759,8 +743,6 @@ - (void)testSignOut {
[_signIn signOut];
XCTAssertNil(_signIn.currentUser, @"should not have a current user");
XCTAssertTrue(_keychainRemoved, @"should remove keychain");
XCTAssertTrue([_changedKeyPaths containsObject:NSStringFromSelector(@selector(currentUser))],
@"should notify observers that signed in user changed");

OCMVerify([_authorization removeAuthorizationFromKeychainForName:kKeychainName
useDataProtectionKeychain:YES]);
Expand Down Expand Up @@ -1445,16 +1427,4 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow
}
}


#pragma mark - Key Value Observing

- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary<NSKeyValueChangeKey, id> *)change
context:(void *)context {
if (context == kTestObserverContext && object == _signIn) {
[_changedKeyPaths addObject:keyPath];
}
}

@end