Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 281
Add the property configuration to GIDGoogleUser#183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,8 +12,12 @@ | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDGoogleUser.h" | ||
| #import "GoogleSignIn/Sources/GIDGoogleUser_Private.h" | ||
| #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDConfiguration.h" | ||
Alex-4-Git marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| #import "GoogleSignIn/Sources/GIDAuthentication_Private.h" | ||
| #import "GoogleSignIn/Sources/GIDProfileData_Private.h" | ||
| @@ -39,6 +43,7 @@ | ||
| @implementation GIDGoogleUser { | ||
| OIDAuthState *_authState; | ||
| GIDConfiguration *_cachedConfiguration; | ||
| } | ||
| - (nullable NSString *)userID { | ||
| @@ -53,30 +58,6 @@ - (nullable NSString *)userID { | ||
| return nil; | ||
| } | ||
| - (nullable NSString *)hostedDomain { | ||
| NSString *idToken = [self idToken]; | ||
| if (idToken) { | ||
| OIDIDToken *idTokenDecoded = [[OIDIDToken alloc] initWithIDTokenString:idToken]; | ||
| if (idTokenDecoded && idTokenDecoded.claims[kHostedDomainIDTokenClaimKey]) { | ||
| return [idTokenDecoded.claims[kHostedDomainIDTokenClaimKey] copy]; | ||
| } | ||
| } | ||
| return nil; | ||
| } | ||
| - (nullable NSString *)serverAuthCode { | ||
| return [_authState.lastTokenResponse.additionalParameters[@"server_code"] copy]; | ||
| } | ||
| - (nullable NSString *)serverClientID { | ||
| return [_authState.lastTokenResponse.request.additionalParameters[kAudienceParameter] copy]; | ||
| } | ||
| - (nullable NSString *)openIDRealm { | ||
| return [_authState.lastTokenResponse.request.additionalParameters[kOpenIDRealmParameter] copy]; | ||
| } | ||
| - (nullable NSArray<NSString *> *)grantedScopes { | ||
| NSArray<NSString *> *grantedScopes; | ||
| NSString *grantedScopeString = _authState.lastTokenResponse.scope; | ||
| @@ -95,6 +76,20 @@ - (nullable NSString *)openIDRealm { | ||
| return grantedScopes; | ||
| } | ||
| - (GIDConfiguration *)configuration { | ||
| @synchronized(self) { | ||
| // Caches the configuration since it would not change for one GIDGoogleUser instance. | ||
| if (!_cachedConfiguration) { | ||
| _cachedConfiguration = [[GIDConfiguration alloc] initWithClientID:[self clientID] | ||
| serverClientID:[self serverClientID] | ||
| hostedDomain:[self hostedDomain] | ||
| openIDRealm:[self openIDRealm]]; | ||
| }; | ||
| } | ||
| return _cachedConfiguration; | ||
| } | ||
| #pragma mark - Private Methods | ||
| - (instancetype)initWithAuthState:(OIDAuthState *)authState | ||
| @@ -115,10 +110,33 @@ - (void)updateAuthState:(OIDAuthState *)authState | ||
| #pragma mark - Helpers | ||
| - (NSString *)clientID { | ||
| return _authState.lastAuthorizationResponse.request.clientID; | ||
| } | ||
| - (nullable NSString *)hostedDomain { | ||
| NSString *idToken = [self idToken]; | ||
| if (idToken) { | ||
| OIDIDToken *idTokenDecoded = [[OIDIDToken alloc] initWithIDTokenString:idToken]; | ||
| if (idTokenDecoded && idTokenDecoded.claims[kHostedDomainIDTokenClaimKey]) { | ||
| return [idTokenDecoded.claims[kHostedDomainIDTokenClaimKey] copy]; | ||
| } | ||
| } | ||
| return nil; | ||
| } | ||
| - (NSString *)idToken { | ||
| return _authState ? _authState.lastTokenResponse.idToken : nil; | ||
| } | ||
| - (nullable NSString *)serverClientID { | ||
| return [_authState.lastTokenResponse.request.additionalParameters[kAudienceParameter] copy]; | ||
| } | ||
| - (nullable NSString *)openIDRealm { | ||
| return [_authState.lastTokenResponse.request.additionalParameters[kOpenIDRealmParameter] copy]; | ||
| } | ||
| #pragma mark - NSSecureCoding | ||
| + (BOOL)supportsSecureCoding { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -14,7 +14,9 @@ | ||
| #import "GoogleSignIn/Tests/Unit/GIDGoogleUser+Testing.h" | ||
| #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDConfiguration.h" | ||
| #import "GoogleSignIn/Tests/Unit/GIDAuthentication+Testing.h" | ||
| #import "GoogleSignIn/Tests/Unit/GIDConfiguration+Testing.h" | ||
| #import "GoogleSignIn/Tests/Unit/GIDProfileData+Testing.h" | ||
| @implementation GIDGoogleUser (Testing) | ||
| @@ -32,15 +34,14 @@ - (BOOL)isEqual:(id)object { | ||
| - (BOOL)isEqualToGoogleUser:(GIDGoogleUser *)other { | ||
| return [self.authentication isEqual:other.authentication] && | ||
| [self.userID isEqual:other.userID] && | ||
| [self.serverAuthCode isEqual:other.serverAuthCode] && | ||
| [self.profile isEqual:other.profile] && | ||
| [self.hostedDomain isEqual:other.hostedDomain]; | ||
| [self.configuration isEqual:other.configuration]; | ||
Alex-4-Git marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| // Not the hash implemention you want to use on prod, but just to match |isEqual:| here. | ||
| - (NSUInteger)hash { | ||
| return [self.authentication hash] ^ [self.userID hash] ^ [self.serverAuthCode hash] ^ | ||
| [self.profile hash] ^ [self.hostedDomain hash]; | ||
| return [self.authentication hash] ^ [self.userID hash] ^ [self.configuration hash] ^ | ||
Alex-4-Git marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| [self.profile hash] ; | ||
| } | ||
| @end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -397,22 +397,29 @@ - (void)testShareInstance { | ||
| - (void)testRestorePreviousSignInNoRefresh_hasPreviousUser { | ||
| [[[_authorization expect] andReturn:_authState] authState]; | ||
| OCMStub([_authState lastTokenResponse]).andReturn(_tokenResponse); | ||
| OCMStub([_tokenResponse scope]).andReturn(nil); | ||
| OCMStub([_tokenResponse additionalParameters]).andReturn(nil); | ||
| OCMStub([_tokenResponse idToken]).andReturn(kFakeIDToken); | ||
| OCMStub([_tokenResponse request]).andReturn(_tokenRequest); | ||
| OCMStub([_tokenRequest additionalParameters]).andReturn(nil); | ||
| id idTokenDecoded = OCMClassMock([OIDIDToken class]); | ||
| OCMStub([idTokenDecoded alloc]).andReturn(idTokenDecoded); | ||
| OCMStub([idTokenDecoded initWithIDTokenString:OCMOCK_ANY]).andReturn(idTokenDecoded); | ||
| OCMStub([idTokenDecoded subject]).andReturn(kFakeGaiaID); | ||
| // Mock generating a GIDConfiguration when initializing GIDGoogleUser. | ||
| OIDAuthorizationResponse *authResponse = | ||
| [OIDAuthorizationResponse testInstanceWithAdditionalParameters:nil | ||
| errorString:nil]; | ||
| OCMStub([_authState lastAuthorizationResponse]).andReturn(authResponse); | ||
| OCMStub([_tokenResponse idToken]).andReturn(kFakeIDToken); | ||
| OCMStub([_tokenResponse request]).andReturn(_tokenRequest); | ||
| OCMStub([_tokenRequest additionalParameters]).andReturn(nil); | ||
Alex-4-Git marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| [_signIn restorePreviousSignInNoRefresh]; | ||
| [_authorization verify]; | ||
| [_authState verify]; | ||
| [_tokenResponse verify]; | ||
| [_tokenRequest verify]; | ||
| [idTokenDecoded verify]; | ||
| XCTAssertEqual(_signIn.currentUser.userID, kFakeGaiaID); | ||
| [idTokenDecoded stopMocking]; | ||
| @@ -569,11 +576,9 @@ - (void)testAddScopes { | ||
| OCMStub([profile email]).andReturn(kUserEmail); | ||
| OCMStub([_user authentication]).andReturn(_authentication); | ||
| OCMStub([_authentication clientID]).andReturn(kClientId); | ||
| OCMStub([_user serverClientID]).andReturn(nil); | ||
| OCMStub([_user hostedDomain]).andReturn(nil); | ||
| OCMStub([_user openIDRealm]).andReturn(kOpenIDRealm); | ||
| // Mock for the method `addScopes`. | ||
| OCMStub([_user configuration]).andReturn(_configuration); | ||
Alex-4-Git marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| OCMStub([_user profile]).andReturn(profile); | ||
| OCMStub([_user grantedScopes]).andReturn(@[kGrantedScope]); | ||
| @@ -603,6 +608,8 @@ - (void)testAddScopes { | ||
| NSArray<NSString *> *expectedScopes = @[kNewScope, kGrantedScope]; | ||
| XCTAssertEqualObjects(grantedScopes, expectedScopes); | ||
| [_user verify]; | ||
| [profile verify]; | ||
| [profile stopMocking]; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.