@@ -367,6 +367,14 @@ - (void)addScopes:(NSArray<NSString *> *)scopes
367367 addScopesFlow: YES
368368 completion: completion];
369369
370+ OIDAuthorizationRequest *lastAuthorizationRequest =
371+ self.currentUser .authState .lastAuthorizationResponse .request ;
372+ NSString *lastTokenClaimsAsJSON =
373+ lastAuthorizationRequest.additionalParameters [kTokenClaimsParameter ];
374+ if (lastTokenClaimsAsJSON) {
375+ options.tokenClaimsAsJSON = lastTokenClaimsAsJSON;
376+ }
377+
370378 NSSet <NSString *> *requestedScopes = [NSSet setWithArray: scopes];
371379 NSMutableSet <NSString *> *grantedScopes =
372380 [NSMutableSet setWithArray: self .currentUser.grantedScopes];
@@ -499,6 +507,14 @@ - (void)addScopes:(NSArray<NSString *> *)scopes
499507 addScopesFlow: YES
500508 completion: completion];
501509
510+ OIDAuthorizationRequest *lastAuthorizationRequest =
511+ self.currentUser .authState .lastAuthorizationResponse .request ;
512+ NSString *lastTokenClaimsAsJSON =
513+ lastAuthorizationRequest.additionalParameters [kTokenClaimsParameter ];
514+ if (lastTokenClaimsAsJSON) {
515+ options.tokenClaimsAsJSON = lastTokenClaimsAsJSON;
516+ }
517+
502518 NSSet <NSString *> *requestedScopes = [NSSet setWithArray: scopes];
503519 NSMutableSet <NSString *> *grantedScopes =
504520 [NSMutableSet setWithArray: self .currentUser.grantedScopes];
@@ -739,20 +755,23 @@ - (void)signInWithOptions:(GIDSignInInternalOptions *)options {
739755 }
740756 }];
741757 } else {
742- NSError *claimsError;
743-
744- // If tokenClaims are invalid or JSON serialization fails, return with an error.
745- options.tokenClaimsAsJSON = [_tokenClaimsInternalOptions
746- validatedJSONStringForClaims: options.tokenClaims
747- error: &claimsError];
748- if (claimsError) {
749- if (options.completion ) {
750- self->_currentOptions = nil ;
751- dispatch_async (dispatch_get_main_queue (), ^{
752- options.completion (nil , claimsError);
753- });
758+ // Only serialize tokenClaims if options.tokenClaimsAsJSON isn't already set.
759+ if (!options.tokenClaimsAsJSON ) {
760+ NSError *claimsError;
761+
762+ // If tokenClaims are invalid or JSON serialization fails, return with an error.
763+ options.tokenClaimsAsJSON = [_tokenClaimsInternalOptions
764+ validatedJSONStringForClaims: options.tokenClaims
765+ error: &claimsError];
766+ if (claimsError) {
767+ if (options.completion ) {
768+ _currentOptions = nil ;
769+ dispatch_async (dispatch_get_main_queue (), ^{
770+ options.completion (nil , claimsError);
771+ });
772+ }
773+ return ;
754774 }
755- return ;
756775 }
757776 [self authenticateWithOptions: options];
758777 }
0 commit comments