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
45 changes: 32 additions & 13 deletions GoogleSignIn/Sources/GIDSignIn.m
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,14 @@ - (void)addScopes:(NSArray<NSString *> *)scopes
addScopesFlow:YES
completion:completion];

OIDAuthorizationRequest *lastAuthorizationRequest =
self.currentUser.authState.lastAuthorizationResponse.request;
NSString *lastTokenClaimsAsJSON =
lastAuthorizationRequest.additionalParameters[kTokenClaimsParameter];
if (lastTokenClaimsAsJSON) {
options.tokenClaimsAsJSON = lastTokenClaimsAsJSON;
}

NSSet<NSString *> *requestedScopes = [NSSet setWithArray:scopes];
NSMutableSet<NSString *> *grantedScopes =
[NSMutableSet setWithArray:self.currentUser.grantedScopes];
Expand Down Expand Up @@ -499,6 +507,14 @@ - (void)addScopes:(NSArray<NSString *> *)scopes
addScopesFlow:YES
completion:completion];

OIDAuthorizationRequest *lastAuthorizationRequest =
self.currentUser.authState.lastAuthorizationResponse.request;
NSString *lastTokenClaimsAsJSON =
lastAuthorizationRequest.additionalParameters[kTokenClaimsParameter];
if (lastTokenClaimsAsJSON) {
options.tokenClaimsAsJSON = lastTokenClaimsAsJSON;
}

NSSet<NSString *> *requestedScopes = [NSSet setWithArray:scopes];
NSMutableSet<NSString *> *grantedScopes =
[NSMutableSet setWithArray:self.currentUser.grantedScopes];
Expand Down Expand Up @@ -739,20 +755,23 @@ - (void)signInWithOptions:(GIDSignInInternalOptions *)options {
}
}];
} else {
NSError *claimsError;

// If tokenClaims are invalid or JSON serialization fails, return with an error.
options.tokenClaimsAsJSON = [_tokenClaimsInternalOptions
validatedJSONStringForClaims:options.tokenClaims
error:&claimsError];
if (claimsError) {
if (options.completion) {
self->_currentOptions = nil;
dispatch_async(dispatch_get_main_queue(), ^{
options.completion(nil, claimsError);
});
// Only serialize tokenClaims if options.tokenClaimsAsJSON isn't already set.
if (!options.tokenClaimsAsJSON) {
NSError *claimsError;

// If tokenClaims are invalid or JSON serialization fails, return with an error.
options.tokenClaimsAsJSON = [_tokenClaimsInternalOptions
validatedJSONStringForClaims:options.tokenClaims
error:&claimsError];
if (claimsError) {
if (options.completion) {
_currentOptions = nil;
dispatch_async(dispatch_get_main_queue(), ^{
options.completion(nil, claimsError);
});
}
return;
}
return;
}
[self authenticateWithOptions:options];
}
Expand Down
Loading