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
2 changes: 1 addition & 1 deletion GoogleSignIn/Sources/GIDGoogleUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ - (void)addScopes:(NSArray<NSString *> *)scopes
#elif TARGET_OS_OSX
presentingWindow:(NSWindow *)presentingWindow
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
completion:(nullable void (^)(GIDSignInResult *_Nullable signInResult,
NSError *_Nullable error))completion {
if (self != GIDSignIn.sharedInstance.currentUser) {
NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain
Expand Down
40 changes: 21 additions & 19 deletions GoogleSignIn/Sources/GIDSignIn.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDConfiguration.h"
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDGoogleUser.h"
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDProfileData.h"
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDUserAuth.h"
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignInResult.h"

#import "GoogleSignIn/Sources/GIDEMMSupport.h"
#import "GoogleSignIn/Sources/GIDSignInInternalOptions.h"
Expand All @@ -34,7 +34,7 @@

#import "GoogleSignIn/Sources/GIDGoogleUser_Private.h"
#import "GoogleSignIn/Sources/GIDProfileData_Private.h"
#import "GoogleSignIn/Sources/GIDUserAuth_Private.h"
#import "GoogleSignIn/Sources/GIDSignInResult_Private.h"

#ifdef SWIFT_PACKAGE
@import AppAuth;
Expand Down Expand Up @@ -201,9 +201,9 @@ - (BOOL)hasPreviousSignIn {
- (void)restorePreviousSignInWithCompletion:(nullable void (^)(GIDGoogleUser *_Nullable user,
NSError *_Nullable error))completion {
[self signInWithOptions:[GIDSignInInternalOptions silentOptionsWithCompletion:
^(GIDUserAuth *userAuth, NSError *error) {
if (userAuth) {
completion(userAuth.user, nil);
^(GIDSignInResult *signInResult, NSError *error) {
if (signInResult) {
completion(signInResult.user, nil);
} else {
completion(nil, error);
}
Expand Down Expand Up @@ -235,7 +235,7 @@ - (BOOL)restorePreviousSignInNoRefresh {

- (void)signInWithPresentingViewController:(UIViewController *)presentingViewController
hint:(nullable NSString *)hint
completion:(nullable GIDUserAuthCompletion)completion {
completion:(nullable GIDSignInCompletion)completion {
GIDSignInInternalOptions *options =
[GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration
presentingViewController:presentingViewController
Expand All @@ -248,7 +248,7 @@ - (void)signInWithPresentingViewController:(UIViewController *)presentingViewCon
- (void)signInWithPresentingViewController:(UIViewController *)presentingViewController
hint:(nullable NSString *)hint
additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
completion:(nullable GIDUserAuthCompletion)completion {
completion:(nullable GIDSignInCompletion)completion {
GIDSignInInternalOptions *options =
[GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration
presentingViewController:presentingViewController
Expand All @@ -260,15 +260,15 @@ - (void)signInWithPresentingViewController:(UIViewController *)presentingViewCon
}

- (void)signInWithPresentingViewController:(UIViewController *)presentingViewController
completion:(nullable GIDUserAuthCompletion)completion {
completion:(nullable GIDSignInCompletion)completion {
[self signInWithPresentingViewController:presentingViewController
hint:nil
completion:completion];
}

- (void)addScopes:(NSArray<NSString *> *)scopes
presentingViewController:(UIViewController *)presentingViewController
completion:(nullable GIDUserAuthCompletion)completion {
completion:(nullable GIDSignInCompletion)completion {
GIDConfiguration *configuration = self.currentUser.configuration;
GIDSignInInternalOptions *options =
[GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
Expand Down Expand Up @@ -306,7 +306,7 @@ - (void)addScopes:(NSArray<NSString *> *)scopes

- (void)signInWithPresentingWindow:(NSWindow *)presentingWindow
hint:(nullable NSString *)hint
completion:(nullable GIDUserAuthCompletion)completion {
completion:(nullable GIDSignInCompletion)completion {
GIDSignInInternalOptions *options =
[GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration
presentingWindow:presentingWindow
Expand All @@ -317,7 +317,7 @@ - (void)signInWithPresentingWindow:(NSWindow *)presentingWindow
}

- (void)signInWithPresentingWindow:(NSWindow *)presentingWindow
completion:(nullable GIDUserAuthCompletion)completion {
completion:(nullable GIDSignInCompletion)completion {
[self signInWithPresentingWindow:presentingWindow
hint:nil
completion:completion];
Expand All @@ -326,7 +326,7 @@ - (void)signInWithPresentingWindow:(NSWindow *)presentingWindow
- (void)signInWithPresentingWindow:(NSWindow *)presentingWindow
hint:(nullable NSString *)hint
additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
completion:(nullable GIDUserAuthCompletion)completion {
completion:(nullable GIDSignInCompletion)completion {
GIDSignInInternalOptions *options =
[GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration
presentingWindow:presentingWindow
Expand All @@ -339,7 +339,7 @@ - (void)signInWithPresentingWindow:(NSWindow *)presentingWindow

- (void)addScopes:(NSArray<NSString *> *)scopes
presentingWindow:(NSWindow *)presentingWindow
completion:(nullable GIDUserAuthCompletion)completion {
completion:(nullable GIDSignInCompletion)completion {
GIDConfiguration *configuration = self.currentUser.configuration;
GIDSignInInternalOptions *options =
[GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
Expand Down Expand Up @@ -529,8 +529,9 @@ - (void)signInWithOptions:(GIDSignInInternalOptions *)options {
if (options.completion) {
self->_currentOptions = nil;
dispatch_async(dispatch_get_main_queue(), ^{
GIDUserAuth *userAuth = [[GIDUserAuth alloc] initWithGoogleUser:self->_currentUser serverAuthCode:nil];
options.completion(userAuth, nil);
GIDSignInResult *signInResult =
[[GIDSignInResult alloc] initWithGoogleUser:self->_currentUser serverAuthCode:nil];
options.completion(signInResult, nil);
});
}
}
Expand Down Expand Up @@ -843,7 +844,7 @@ - (void)addCompletionCallback:(GIDAuthFlow *)authFlow {
[authFlow addCallback:^() {
GIDAuthFlow *handlerAuthFlow = weakAuthFlow;
if (self->_currentOptions.completion) {
GIDUserAuthCompletion completion = self->_currentOptions.completion;
GIDSignInCompletion completion = self->_currentOptions.completion;
self->_currentOptions = nil;
dispatch_async(dispatch_get_main_queue(), ^{
if (handlerAuthFlow.error) {
Expand All @@ -852,9 +853,10 @@ - (void)addCompletionCallback:(GIDAuthFlow *)authFlow {
OIDAuthState *authState = handlerAuthFlow.authState;
NSString *_Nullable serverAuthCode =
[authState.lastTokenResponse.additionalParameters[@"server_code"] copy];
GIDUserAuth *userAuth = [[GIDUserAuth alloc] initWithGoogleUser:self->_currentUser
serverAuthCode:serverAuthCode];
completion(userAuth, nil);
GIDSignInResult *signInResult =
[[GIDSignInResult alloc] initWithGoogleUser:self->_currentUser
serverAuthCode:serverAuthCode];
completion(signInResult, nil);
}
});
}
Expand Down
22 changes: 9 additions & 13 deletions GoogleSignIn/Sources/GIDSignInInternalOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
#import <AppKit/AppKit.h>
#endif

#import "GoogleSignIn/Sources/GIDSignIn_Private.h"

@class GIDConfiguration;
@class GIDUserAuth;
@class GIDSignInResult;

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -54,8 +56,7 @@ NS_ASSUME_NONNULL_BEGIN
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST

/// The completion block to be called at the completion of the flow.
@property(nonatomic, readonly, nullable) void (^completion)(GIDUserAuth *_Nullable userAuth,
NSError *_Nullable error);
@property(nonatomic, readonly, nullable) GIDSignInCompletion completion;

/// The scopes to be used during the flow.
@property(nonatomic, copy, nullable) NSArray<NSString *> *scopes;
Expand All @@ -69,37 +70,32 @@ NS_ASSUME_NONNULL_BEGIN
presentingViewController:(nullable UIViewController *)presentingViewController
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
NSError *_Nullable error))completion;
completion:(nullable GIDSignInCompletion)completion;

+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
presentingViewController:(nullable UIViewController *)presentingViewController
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
scopes:(nullable NSArray *)scopes
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
NSError *_Nullable error))completion;
completion:(nullable GIDSignInCompletion)completion;

#elif TARGET_OS_OSX
+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
presentingWindow:(nullable NSWindow *)presentingWindow
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
NSError *_Nullable error))completion;
completion:(nullable GIDSignInCompletion)completion;

+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
presentingWindow:(nullable NSWindow *)presentingWindow
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
scopes:(nullable NSArray *)scopes
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
NSError *_Nullable error))completion;
completion:(nullable GIDSignInCompletion)completion;
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST

/// Creates the options to sign in silently.
+ (instancetype)silentOptionsWithCompletion:(void (^)(GIDUserAuth *_Nullable userAuth,
NSError *_Nullable error))completion;
+ (instancetype)silentOptionsWithCompletion:(GIDSignInCompletion)completion;

/// Creates options with the same values as the receiver, except for the "extra parameters", and
/// continuation flag, which are replaced by the arguments passed to this method.
Expand Down
15 changes: 5 additions & 10 deletions GoogleSignIn/Sources/GIDSignInInternalOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)con
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
scopes:(nullable NSArray *)scopes
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
NSError *_Nullable error))completion {
completion:(nullable GIDSignInCompletion)completion {
#elif TARGET_OS_OSX
+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
presentingWindow:(nullable NSWindow *)presentingWindow
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
scopes:(nullable NSArray *)scopes
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
NSError *_Nullable error))completion {
completion:(nullable GIDSignInCompletion)completion {
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
GIDSignInInternalOptions *options = [[GIDSignInInternalOptions alloc] init];
if (options) {
Expand All @@ -65,15 +63,13 @@ + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)con
presentingViewController:(nullable UIViewController *)presentingViewController
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
NSError *_Nullable error))completion {
completion:(nullable GIDSignInCompletion)completion {
#elif TARGET_OS_OSX
+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
presentingWindow:(nullable NSWindow *)presentingWindow
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
NSError *_Nullable error))completion {
completion:(nullable GIDSignInCompletion)completion {
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:configuration
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
Expand All @@ -88,8 +84,7 @@ + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)con
return options;
}

+ (instancetype)silentOptionsWithCompletion:(void (^)(GIDUserAuth *_Nullable userAuth,
NSError *_Nullable error))completion {
+ (instancetype)silentOptionsWithCompletion:(GIDSignInCompletion)completion {
GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:nil
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
presentingViewController:nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Google LLC
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,12 +14,12 @@
* limitations under the License.
*/

#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDUserAuth.h"
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignInResult.h"

#import "GoogleSignIn/Sources/GIDUserAuth_Private.h"
#import "GoogleSignIn/Sources/GIDSignInResult_Private.h"
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDGoogleUser.h"

@implementation GIDUserAuth
@implementation GIDSignInResult

- (instancetype)initWithGoogleUser:(GIDGoogleUser *)user
serverAuthCode:(nullable NSString *)serverAuthCode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDUserAuth.h"
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignInResult.h"

NS_ASSUME_NONNULL_BEGIN

// Private |GIDUserAuth| methods that are used in this SDK.
@interface GIDUserAuth ()
// Private |GIDSignInResult| methods that are used in this SDK.
@interface GIDSignInResult ()

// Private initializer for |GIDUserAuth|.
// Private initializer for |GIDSignInResult|.
// @param user The current GIDGoogleUser.
// @param severAuthCode The one-time authorization code for backend to exchange
// access and refresh tokens.
Expand Down
17 changes: 8 additions & 9 deletions GoogleSignIn/Sources/GIDSignIn_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ NS_ASSUME_NONNULL_BEGIN
@class GIDGoogleUser;
@class GIDSignInInternalOptions;

/// Represents a completion block that takes a `GIDUserAuth` on success or an error if the operation
/// was unsuccessful.
typedef void (^GIDUserAuthCompletion)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error);
/// Represents a completion block that takes a `GIDSignInResult` on success or an error if the
/// operation was unsuccessful.
typedef void (^GIDSignInCompletion)(GIDSignInResult *_Nullable signInResult,
NSError *_Nullable error);

/// Represents a completion block that takes an error if the operation was unsuccessful.
typedef void (^GIDDisconnectCompletion)(NSError *_Nullable error);
Expand Down Expand Up @@ -60,7 +61,7 @@ typedef void (^GIDDisconnectCompletion)(NSError *_Nullable error);

/// Starts an interactive consent flow on iOS to add scopes to the current user's grants.
///
/// The completion will be called at the end of this process. If successful, a `GIDUserAuth`
/// The completion will be called at the end of this process. If successful, a `GIDSignInResult`
/// instance will be returned reflecting the new scopes and saved sign-in state will be updated.
///
/// @param scopes The scopes to ask the user to consent to.
Expand All @@ -71,15 +72,14 @@ typedef void (^GIDDisconnectCompletion)(NSError *_Nullable error);
/// on the main queue.
- (void)addScopes:(NSArray<NSString *> *)scopes
presentingViewController:(UIViewController *)presentingViewController
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
NSError *_Nullable error))completion
completion:(nullable GIDSignInCompletion)completion
NS_EXTENSION_UNAVAILABLE("The add scopes flow is not supported in App Extensions.");

#elif TARGET_OS_OSX

/// Starts an interactive consent flow on macOS to add scopes to the current user's grants.
///
/// The completion will be called at the end of this process. If successful, a `GIDUserAuth`
/// The completion will be called at the end of this process. If successful, a `GIDSignInResult`
/// instance will be returned reflecting the new scopes and saved sign-in state will be updated.
///
/// @param scopes An array of scopes to ask the user to consent to.
Expand All @@ -89,8 +89,7 @@ typedef void (^GIDDisconnectCompletion)(NSError *_Nullable error);
/// on the main queue.
- (void)addScopes:(NSArray<NSString *> *)scopes
presentingWindow:(NSWindow *)presentingWindow
completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
NSError *_Nullable error))completion;
completion:(nullable GIDSignInCompletion)completion;

#endif

Expand Down
Loading