Skip to content

Commit 325a706

Browse files
committed
Merge branch 'main' into briannamorales/vwg-flow
2 parents 3170234 + 72b9e63 commit 325a706

File tree

15 files changed

+237
-39
lines changed

15 files changed

+237
-39
lines changed

GoogleSignIn/Sources/GIDAuthorizationResponse/Implementations/GIDAuthorizationResponseHandler.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ - (void)maybeFetchToken:(GIDAuthFlow *)authFlow {
141141

142142
// TODO: Clean up callback flow (#427).
143143
[authFlow wait];
144-
[OIDAuthorizationService
145-
performTokenRequest:tokenRequest
146-
callback:^(OIDTokenResponse *_Nullable tokenResponse,
147-
NSError *_Nullable error) {
144+
[OIDAuthorizationService performTokenRequest:tokenRequest
145+
originalAuthorizationResponse:authFlow.authState.lastAuthorizationResponse
146+
callback:^(OIDTokenResponse *_Nullable tokenResponse,
147+
NSError *_Nullable error) {
148148
[authState updateWithTokenResponse:tokenResponse error:error];
149149
authFlow.error = error;
150150

@@ -211,7 +211,8 @@ - (void)authorizationResponseErrorToAuthFlow:(GIDAuthFlow *)authFlow
211211
switch (_flowName) {
212212
case GIDFlowNameSignIn: {
213213
GIDSignInErrorCode errorCode = kGIDSignInErrorCodeUnknown;
214-
if (error.code == OIDErrorCodeUserCanceledAuthorizationFlow) {
214+
if (error.code == OIDErrorCodeUserCanceledAuthorizationFlow ||
215+
error.code == OIDErrorCodeProgramCanceledAuthorizationFlow) {
215216
// The user has canceled the flow at the iOS modal dialog.
216217
errorString = kUserCanceledSignInError;
217218
errorCode = kGIDSignInErrorCodeCanceled;

GoogleSignIn/Sources/GIDSignIn.m

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,25 @@ - (void)signInWithPresentingViewController:(UIViewController *)presentingViewCon
234234
hint:(nullable NSString *)hint
235235
additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
236236
completion:(nullable GIDSignInCompletion)completion {
237+
[self signInWithPresentingViewController:presentingViewController
238+
hint:hint
239+
additionalScopes:additionalScopes
240+
nonce:nil
241+
completion:completion];
242+
}
243+
244+
- (void)signInWithPresentingViewController:(UIViewController *)presentingViewController
245+
hint:(nullable NSString *)hint
246+
additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
247+
nonce:(nullable NSString *)nonce
248+
completion:(nullable GIDSignInCompletion)completion {
237249
GIDSignInInternalOptions *options =
238250
[GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration
239251
presentingViewController:presentingViewController
240252
loginHint:hint
241253
addScopesFlow:NO
242254
scopes:additionalScopes
255+
nonce:nonce
243256
completion:completion];
244257
[self signInWithOptions:options];
245258
}
@@ -315,12 +328,25 @@ - (void)signInWithPresentingWindow:(NSWindow *)presentingWindow
315328
hint:(nullable NSString *)hint
316329
additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
317330
completion:(nullable GIDSignInCompletion)completion {
331+
[self signInWithPresentingWindow:presentingWindow
332+
hint:hint
333+
additionalScopes:additionalScopes
334+
nonce:nil
335+
completion:completion];
336+
}
337+
338+
- (void)signInWithPresentingWindow:(NSWindow *)presentingWindow
339+
hint:(nullable NSString *)hint
340+
additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
341+
nonce:(nullable NSString *)nonce
342+
completion:(nullable GIDSignInCompletion)completion {
318343
GIDSignInInternalOptions *options =
319344
[GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration
320345
presentingWindow:presentingWindow
321346
loginHint:hint
322347
addScopesFlow:NO
323348
scopes:additionalScopes
349+
nonce:nonce
324350
completion:completion];
325351
[self signInWithOptions:options];
326352
}
@@ -539,7 +565,7 @@ - (void)signInWithOptions:(GIDSignInInternalOptions *)options {
539565
if (!_configuration) {
540566
// NOLINTNEXTLINE(google-objc-avoid-throwing-exception)
541567
[NSException raise:NSInvalidArgumentException
542-
format:@"No active configuration. Make sure GIDClientID is set in Info.plist."];
568+
format:@"No active configuration. Make sure GIDClientID is set in Info.plist."];
543569
return;
544570
}
545571

@@ -633,7 +659,6 @@ - (void)authorizationRequestWithOptions:(GIDSignInInternalOptions *)options comp
633659
[_timedLoader startTiming];
634660
[self->_appCheck getLimitedUseTokenWithCompletion:^(GACAppCheckToken * _Nullable token,
635661
NSError * _Nullable error) {
636-
OIDAuthorizationRequest *request = nil;
637662
if (token) {
638663
additionalParameters[kClientAssertionTypeParameter] = kClientAssertionTypeParameterValue;
639664
additionalParameters[kClientAssertionParameter] = token.token;
@@ -643,7 +668,7 @@ - (void)authorizationRequestWithOptions:(GIDSignInInternalOptions *)options comp
643668
NSLog(@"[Google Sign-In iOS]: Error retrieving App Check limited use token: %@", error);
644669
}
645670
#endif
646-
request = [self authorizationRequestWithOptions:options
671+
OIDAuthorizationRequest *request = [self authorizationRequestWithOptions:options
647672
additionalParameters:additionalParameters];
648673
if (self->_timedLoader.animationStatus == GIDTimedLoaderAnimationStatusAnimating) {
649674
[self->_timedLoader stopTimingWithCompletion:^{
@@ -667,13 +692,23 @@ - (void)authorizationRequestWithOptions:(GIDSignInInternalOptions *)options comp
667692
- (OIDAuthorizationRequest *)
668693
authorizationRequestWithOptions:(GIDSignInInternalOptions *)options
669694
additionalParameters:(NSDictionary<NSString *, NSString *> *)additionalParameters {
670-
OIDAuthorizationRequest *request =
671-
[[OIDAuthorizationRequest alloc] initWithConfiguration:_appAuthConfiguration
672-
clientId:options.configuration.clientID
673-
scopes:options.scopes
674-
redirectURL:[self redirectURLWithOptions:options]
675-
responseType:OIDResponseTypeCode
676-
additionalParameters:additionalParameters];
695+
OIDAuthorizationRequest *request;
696+
if (options.nonce) {
697+
request = [[OIDAuthorizationRequest alloc] initWithConfiguration:_appAuthConfiguration
698+
clientId:options.configuration.clientID
699+
scopes:options.scopes
700+
redirectURL:[self redirectURLWithOptions:options]
701+
responseType:OIDResponseTypeCode
702+
nonce:options.nonce
703+
additionalParameters:additionalParameters];
704+
} else {
705+
request = [[OIDAuthorizationRequest alloc] initWithConfiguration:_appAuthConfiguration
706+
clientId:options.configuration.clientID
707+
scopes:options.scopes
708+
redirectURL:[self redirectURLWithOptions:options]
709+
responseType:OIDResponseTypeCode
710+
additionalParameters:additionalParameters];
711+
}
677712
return request;
678713
}
679714

@@ -724,7 +759,7 @@ - (NSURL *)redirectURLWithOptions:(GIDSignInInternalOptions *)options {
724759

725760
- (void)processAuthorizationResponse:(nullable OIDAuthorizationResponse *)authorizationResponse
726761
error:(nullable NSError *)error
727-
emmSupport:(NSString *)emmSupport{
762+
emmSupport:(NSString *)emmSupport {
728763
if (_restarting) {
729764
// The auth flow is restarting, so the work here would be performed in the next round.
730765
_restarting = NO;

GoogleSignIn/Sources/GIDSignInInternalOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ NS_ASSUME_NONNULL_BEGIN
7878
/// The login hint to be used during the flow.
7979
@property(nonatomic, copy, nullable) NSString *loginHint;
8080

81+
/// A cryptographically random value used to associate a Client session with an ID Token,
82+
/// and to mitigate replay attacks.
83+
@property(nonatomic, readonly, copy, nullable) NSString *nonce;
84+
8185
/// Creates the default options.
8286
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
8387
+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
@@ -100,6 +104,7 @@ NS_ASSUME_NONNULL_BEGIN
100104
loginHint:(nullable NSString *)loginHint
101105
addScopesFlow:(BOOL)addScopesFlow
102106
scopes:(nullable NSArray *)scopes
107+
nonce:(nullable NSString *)nonce
103108
completion:(nullable GIDSignInCompletion)completion;
104109
#elif TARGET_OS_OSX
105110
+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
@@ -113,6 +118,7 @@ NS_ASSUME_NONNULL_BEGIN
113118
loginHint:(nullable NSString *)loginHint
114119
addScopesFlow:(BOOL)addScopesFlow
115120
scopes:(nullable NSArray *)scopes
121+
nonce:(nullable NSString *)nonce
116122
completion:(nullable GIDSignInCompletion)completion;
117123
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
118124

GoogleSignIn/Sources/GIDSignInInternalOptions.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)con
5454
loginHint:(nullable NSString *)loginHint
5555
addScopesFlow:(BOOL)addScopesFlow
5656
scopes:(nullable NSArray *)scopes
57+
nonce:(nullable NSString *)nonce
5758
completion:(nullable GIDSignInCompletion)completion {
5859
#elif TARGET_OS_OSX
5960
+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
6061
presentingWindow:(nullable NSWindow *)presentingWindow
6162
loginHint:(nullable NSString *)loginHint
6263
addScopesFlow:(BOOL)addScopesFlow
6364
scopes:(nullable NSArray *)scopes
65+
nonce:(nullable NSString *)nonce
6466
completion:(nullable GIDSignInCompletion)completion {
6567
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
6668
GIDSignInInternalOptions *options = [[GIDSignInInternalOptions alloc] init];
@@ -77,6 +79,7 @@ + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)con
7779
options->_loginHint = loginHint;
7880
options->_completion = completion;
7981
options->_scopes = [GIDScopes scopesWithBasicProfile:scopes];
82+
options->_nonce = nonce;
8083
}
8184
return options;
8285
}
@@ -103,6 +106,7 @@ + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)con
103106
loginHint:loginHint
104107
addScopesFlow:addScopesFlow
105108
scopes:@[]
109+
nonce:nil
106110
completion:completion];
107111
return options;
108112
}

GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,31 @@ NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions.")
196196
NSError *_Nullable error))completion
197197
NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions.");
198198

199+
200+
/// Starts an interactive sign-in flow on iOS using the provided hint, additional scopes, and nonce.
201+
///
202+
/// The completion will be called at the end of this process. Any saved sign-in state will be
203+
/// replaced by the result of this flow. Note that this method should not be called when the app is
204+
/// starting up, (e.g in `application:didFinishLaunchingWithOptions:`); instead use the
205+
/// `restorePreviousSignInWithCompletion:` method to restore a previous sign-in.
206+
///
207+
/// @param presentingViewController The view controller used to present `SFSafariViewController` on
208+
/// iOS 9 and 10.
209+
/// @param hint An optional hint for the authorization server, for example the user's ID or email
210+
/// address, to be prefilled if possible.
211+
/// @param additionalScopes An optional array of scopes to request in addition to the basic profile scopes.
212+
/// @param nonce A custom nonce.
213+
/// @param completion The optional block that is called on completion. This block will
214+
/// be called asynchronously on the main queue.
215+
- (void)signInWithPresentingViewController:(UIViewController *)presentingViewController
216+
hint:(nullable NSString *)hint
217+
additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
218+
nonce:(nullable NSString *)nonce
219+
completion:
220+
(nullable void (^)(GIDSignInResult *_Nullable signInResult,
221+
NSError *_Nullable error))completion
222+
NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions.");
223+
199224
#elif TARGET_OS_OSX
200225

201226
/// Starts an interactive sign-in flow on macOS.
@@ -229,7 +254,7 @@ NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions.")
229254
completion:(nullable void (^)(GIDSignInResult *_Nullable signInResult,
230255
NSError *_Nullable error))completion;
231256

232-
/// Starts an interactive sign-in flow on macOS using the provided hint.
257+
/// Starts an interactive sign-in flow on macOS using the provided hint and additional scopes.
233258
///
234259
/// The completion will be called at the end of this process. Any saved sign-in state will be
235260
/// replaced by the result of this flow. Note that this method should not be called when the app is
@@ -248,6 +273,28 @@ NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions.")
248273
completion:(nullable void (^)(GIDSignInResult *_Nullable signInResult,
249274
NSError *_Nullable error))completion;
250275

276+
/// Starts an interactive sign-in flow on macOS using the provided hint, additional scopes, and nonce.
277+
///
278+
/// The completion will be called at the end of this process. Any saved sign-in state will be
279+
/// replaced by the result of this flow. Note that this method should not be called when the app is
280+
/// starting up, (e.g in `application:didFinishLaunchingWithOptions:`); instead use the
281+
/// `restorePreviousSignInWithCompletion:` method to restore a previous sign-in.
282+
///
283+
/// @param presentingWindow The window used to supply `presentationContextProvider` for `ASWebAuthenticationSession`.
284+
/// @param hint An optional hint for the authorization server, for example the user's ID or email
285+
/// address, to be prefilled if possible.
286+
/// @param additionalScopes An optional array of scopes to request in addition to the basic profile scopes.
287+
/// @param nonce A custom nonce.
288+
/// @param completion The optional block that is called on completion. This block will
289+
/// be called asynchronously on the main queue.
290+
- (void)signInWithPresentingWindow:(NSWindow *)presentingWindow
291+
hint:(nullable NSString *)hint
292+
additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
293+
nonce:(nullable NSString *)nonce
294+
completion:(nullable void (^)(GIDSignInResult *_Nullable signInResult,
295+
NSError *_Nullable error))completion;
296+
297+
251298
#endif
252299

253300
@end

0 commit comments

Comments
 (0)