Skip to content

Commit d22b4fd

Browse files
committed
Updated SignInFlow with improved tokenClaims processing
1 parent d584605 commit d22b4fd

File tree

4 files changed

+10
-35
lines changed

4 files changed

+10
-35
lines changed

GoogleSignIn/Sources/GIDSignIn.m

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,10 @@ - (void)signInWithOptions:(GIDSignInInternalOptions *)options {
742742
NSError *claimsError;
743743

744744
// If tokenClaims are invalid or JSON serialization fails, return with an error.
745-
if (![self processTokenClaimsForOptions:options error:&claimsError]) {
745+
options.tokenClaimsAsJSON = [_tokenClaimsInternalOptions
746+
validatedJSONStringForClaims:options.tokenClaims
747+
error:&claimsError];
748+
if (claimsError) {
746749
if (options.completion) {
747750
self->_currentOptions = nil;
748751
dispatch_async(dispatch_get_main_queue(), ^{
@@ -1267,24 +1270,6 @@ - (void)assertValidPresentingViewController {
12671270
}
12681271
}
12691272

1270-
- (BOOL)processTokenClaimsForOptions:(GIDSignInInternalOptions *)options
1271-
error:(NSError **)error {
1272-
if (!options.tokenClaims) {
1273-
return YES; // Success
1274-
}
1275-
1276-
NSString *tokenClaimsAsJSON =
1277-
[_tokenClaimsInternalOptions validatedJSONStringForClaims:options.tokenClaims
1278-
error:error];
1279-
1280-
if (!tokenClaimsAsJSON) {
1281-
return NO; // Failure
1282-
}
1283-
1284-
options.tokenClaimsAsJSON = tokenClaimsAsJSON;
1285-
return YES; // Success
1286-
}
1287-
12881273
// Checks whether or not this is the first time the app runs.
12891274
- (BOOL)isFreshInstall {
12901275
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];

GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions.")
233233
/// starting up, (e.g in `application:didFinishLaunchingWithOptions:`); instead use the
234234
/// `restorePreviousSignInWithCompletion:` method to restore a previous sign-in.
235235
///
236-
/// @param presentingViewController The view controller used to present `SFSafariViewController` on
237-
/// iOS 9 and 10.
236+
/// @param presentingViewController The view controller used to present the authorization flow.
238237
/// @param tokenClaims An optional `NSSet` of tokenClaims to request.
239238
/// @param completion The optional block that is called on completion. This block will
240239
/// be called asynchronously on the main queue.
@@ -245,15 +244,14 @@ NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions.")
245244
NSError *_Nullable error))completion
246245
NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions.");
247246

248-
/// Starts an interactive sign-in flow on iOS using the provided hint, and tokenClaims.
247+
/// Starts an interactive sign-in flow on iOS using the provided hint and tokenClaims.
249248
///
250249
/// The completion will be called at the end of this process. Any saved sign-in state will be
251250
/// replaced by the result of this flow. Note that this method should not be called when the app is
252251
/// starting up, (e.g in `application:didFinishLaunchingWithOptions:`); instead use the
253252
/// `restorePreviousSignInWithCompletion:` method to restore a previous sign-in.
254253
///
255-
/// @param presentingViewController The view controller used to present `SFSafariViewController` on
256-
/// iOS 9 and 10.
254+
/// @param presentingViewController The view controller used to present the authorization flow.
257255
/// @param hint An optional hint for the authorization server, for example the user's ID or email
258256
/// address, to be prefilled if possible.
259257
/// @param tokenClaims An optional `NSSet` of tokenClaims to request.
@@ -275,8 +273,7 @@ NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions.")
275273
/// starting up, (e.g in `application:didFinishLaunchingWithOptions:`); instead use the
276274
/// `restorePreviousSignInWithCompletion:` method to restore a previous sign-in.
277275
///
278-
/// @param presentingViewController The view controller used to present `SFSafariViewController` on
279-
/// iOS 9 and 10.
276+
/// @param presentingViewController The view controller used to present the authorization flow.
280277
/// @param hint An optional hint for the authorization server, for example the user's ID or email
281278
/// address, to be prefilled if possible.
282279
/// @param additionalScopes An optional array of scopes to request in addition to the basic profile scopes.
@@ -292,16 +289,15 @@ NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions.")
292289
NSError *_Nullable error))completion
293290
NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions.");
294291

295-
/// Starts an interactive sign-in flow on iOS using the provided hint, additional scopes, nonce
292+
/// Starts an interactive sign-in flow on iOS using the provided hint, additional scopes, nonce,
296293
/// and tokenClaims.
297294
///
298295
/// The completion will be called at the end of this process. Any saved sign-in state will be
299296
/// replaced by the result of this flow. Note that this method should not be called when the app is
300297
/// starting up, (e.g in `application:didFinishLaunchingWithOptions:`); instead use the
301298
/// `restorePreviousSignInWithCompletion:` method to restore a previous sign-in.
302299
///
303-
/// @param presentingViewController The view controller used to present `SFSafariViewController` on
304-
/// iOS 9 and 10.
300+
/// @param presentingViewController The view controller used to present the authorization flow.
305301
/// @param hint An optional hint for the authorization server, for example the user's ID or email
306302
/// address, to be prefilled if possible.
307303
/// @param additionalScopes An optional array of scopes to request in addition to the basic profile scopes.

GoogleSignIn/Tests/Unit/GIDSignInInternalOptionsTest.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ - (void)testDefaultOptions_withAllParameters_initializesPropertiesCorrectly {
7575
NSArray<NSString *> *scopes = @[@"scope1", @"scope2"];
7676
NSString *nonce = @"test_nonce";
7777
NSSet<GIDTokenClaim *> *tokenClaims = [NSSet setWithObject:[GIDTokenClaim authTimeClaim]];
78-
79-
// The expected scopes array will contain the provided scopes plus the default profile scopes.
8078
NSArray<NSString *> *expectedScopes = @[@"scope1", @"scope2", @"email", @"profile"];
8179

8280
GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult,

GoogleSignIn/Tests/Unit/GIDSignInTest.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
//
99
// Unless required by applicable law or agreed to in writing, software
1010
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR COhttp://www.apache.org/licenses/LICENSE-2.0
1211
//
1312
// Unless required by applicable law or agreed to in writing, software
1413
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -1638,9 +1637,6 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow
16381637
}
16391638

16401639
if (tokenClaimsError) {
1641-
XCTestExpectation *tokenClaimsErrorExpectation =
1642-
[self expectationWithDescription:@"Callback called"];
1643-
[tokenClaimsErrorExpectation fulfill];
16441640
return;
16451641
}
16461642

0 commit comments

Comments
 (0)