diff --git a/GoogleSignIn/Sources/GIDGoogleUser.m b/GoogleSignIn/Sources/GIDGoogleUser.m index d6ab89b7..828ac5b6 100644 --- a/GoogleSignIn/Sources/GIDGoogleUser.m +++ b/GoogleSignIn/Sources/GIDGoogleUser.m @@ -189,7 +189,7 @@ - (void)addScopes:(NSArray *)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 diff --git a/GoogleSignIn/Sources/GIDSignIn.m b/GoogleSignIn/Sources/GIDSignIn.m index 4690781e..429c1666 100644 --- a/GoogleSignIn/Sources/GIDSignIn.m +++ b/GoogleSignIn/Sources/GIDSignIn.m @@ -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" @@ -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; @@ -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); } @@ -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 @@ -248,7 +248,7 @@ - (void)signInWithPresentingViewController:(UIViewController *)presentingViewCon - (void)signInWithPresentingViewController:(UIViewController *)presentingViewController hint:(nullable NSString *)hint additionalScopes:(nullable NSArray *)additionalScopes - completion:(nullable GIDUserAuthCompletion)completion { + completion:(nullable GIDSignInCompletion)completion { GIDSignInInternalOptions *options = [GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration presentingViewController:presentingViewController @@ -260,7 +260,7 @@ - (void)signInWithPresentingViewController:(UIViewController *)presentingViewCon } - (void)signInWithPresentingViewController:(UIViewController *)presentingViewController - completion:(nullable GIDUserAuthCompletion)completion { + completion:(nullable GIDSignInCompletion)completion { [self signInWithPresentingViewController:presentingViewController hint:nil completion:completion]; @@ -268,7 +268,7 @@ - (void)signInWithPresentingViewController:(UIViewController *)presentingViewCon - (void)addScopes:(NSArray *)scopes presentingViewController:(UIViewController *)presentingViewController - completion:(nullable GIDUserAuthCompletion)completion { + completion:(nullable GIDSignInCompletion)completion { GIDConfiguration *configuration = self.currentUser.configuration; GIDSignInInternalOptions *options = [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration @@ -306,7 +306,7 @@ - (void)addScopes:(NSArray *)scopes - (void)signInWithPresentingWindow:(NSWindow *)presentingWindow hint:(nullable NSString *)hint - completion:(nullable GIDUserAuthCompletion)completion { + completion:(nullable GIDSignInCompletion)completion { GIDSignInInternalOptions *options = [GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration presentingWindow:presentingWindow @@ -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]; @@ -326,7 +326,7 @@ - (void)signInWithPresentingWindow:(NSWindow *)presentingWindow - (void)signInWithPresentingWindow:(NSWindow *)presentingWindow hint:(nullable NSString *)hint additionalScopes:(nullable NSArray *)additionalScopes - completion:(nullable GIDUserAuthCompletion)completion { + completion:(nullable GIDSignInCompletion)completion { GIDSignInInternalOptions *options = [GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration presentingWindow:presentingWindow @@ -339,7 +339,7 @@ - (void)signInWithPresentingWindow:(NSWindow *)presentingWindow - (void)addScopes:(NSArray *)scopes presentingWindow:(NSWindow *)presentingWindow - completion:(nullable GIDUserAuthCompletion)completion { + completion:(nullable GIDSignInCompletion)completion { GIDConfiguration *configuration = self.currentUser.configuration; GIDSignInInternalOptions *options = [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration @@ -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); }); } } @@ -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) { @@ -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); } }); } diff --git a/GoogleSignIn/Sources/GIDSignInInternalOptions.h b/GoogleSignIn/Sources/GIDSignInInternalOptions.h index a51bfd95..f1aff409 100644 --- a/GoogleSignIn/Sources/GIDSignInInternalOptions.h +++ b/GoogleSignIn/Sources/GIDSignInInternalOptions.h @@ -22,8 +22,10 @@ #import #endif +#import "GoogleSignIn/Sources/GIDSignIn_Private.h" + @class GIDConfiguration; -@class GIDUserAuth; +@class GIDSignInResult; NS_ASSUME_NONNULL_BEGIN @@ -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 *scopes; @@ -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. diff --git a/GoogleSignIn/Sources/GIDSignInInternalOptions.m b/GoogleSignIn/Sources/GIDSignInInternalOptions.m index dfa39aa1..bfb21643 100644 --- a/GoogleSignIn/Sources/GIDSignInInternalOptions.m +++ b/GoogleSignIn/Sources/GIDSignInInternalOptions.m @@ -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) { @@ -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 @@ -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 diff --git a/GoogleSignIn/Sources/GIDUserAuth.m b/GoogleSignIn/Sources/GIDSignInResult.m similarity index 82% rename from GoogleSignIn/Sources/GIDUserAuth.m rename to GoogleSignIn/Sources/GIDSignInResult.m index 90dfa289..20f811b8 100644 --- a/GoogleSignIn/Sources/GIDUserAuth.m +++ b/GoogleSignIn/Sources/GIDSignInResult.m @@ -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. @@ -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 { diff --git a/GoogleSignIn/Sources/GIDUserAuth_Private.h b/GoogleSignIn/Sources/GIDSignInResult_Private.h similarity index 81% rename from GoogleSignIn/Sources/GIDUserAuth_Private.h rename to GoogleSignIn/Sources/GIDSignInResult_Private.h index c3f1f728..aa78a134 100644 --- a/GoogleSignIn/Sources/GIDUserAuth_Private.h +++ b/GoogleSignIn/Sources/GIDSignInResult_Private.h @@ -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. diff --git a/GoogleSignIn/Sources/GIDSignIn_Private.h b/GoogleSignIn/Sources/GIDSignIn_Private.h index 811a6b28..825327ba 100644 --- a/GoogleSignIn/Sources/GIDSignIn_Private.h +++ b/GoogleSignIn/Sources/GIDSignIn_Private.h @@ -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); @@ -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. @@ -71,15 +72,14 @@ typedef void (^GIDDisconnectCompletion)(NSError *_Nullable error); /// on the main queue. - (void)addScopes:(NSArray *)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. @@ -89,8 +89,7 @@ typedef void (^GIDDisconnectCompletion)(NSError *_Nullable error); /// on the main queue. - (void)addScopes:(NSArray *)scopes presentingWindow:(NSWindow *)presentingWindow - completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth, - NSError *_Nullable error))completion; + completion:(nullable GIDSignInCompletion)completion; #endif diff --git a/GoogleSignIn/Sources/Public/GoogleSignIn/GIDGoogleUser.h b/GoogleSignIn/Sources/Public/GoogleSignIn/GIDGoogleUser.h index f0555b83..8cc0bdff 100644 --- a/GoogleSignIn/Sources/Public/GoogleSignIn/GIDGoogleUser.h +++ b/GoogleSignIn/Sources/Public/GoogleSignIn/GIDGoogleUser.h @@ -32,7 +32,7 @@ #endif @class GIDConfiguration; -@class GIDUserAuth; +@class GIDSignInResult; @class GIDToken; @class GIDProfileData; @@ -82,7 +82,7 @@ NS_ASSUME_NONNULL_BEGIN /// Starts an interactive consent flow on iOS to add new scopes to the user's `grantedScopes`. /// -/// 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. @@ -93,7 +93,7 @@ NS_ASSUME_NONNULL_BEGIN /// asynchronously on the main queue. - (void)addScopes:(NSArray *)scopes presentingViewController:(UIViewController *)presentingViewController - completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth, + completion:(nullable void (^)(GIDSignInResult *_Nullable signInResult, NSError *_Nullable error))completion NS_EXTENSION_UNAVAILABLE("The add scopes flow is not supported in App Extensions."); @@ -101,7 +101,7 @@ NS_ASSUME_NONNULL_BEGIN /// Starts an interactive consent flow on macOS to add new scopes to the user's `grantedScopes`. /// -/// 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. @@ -111,7 +111,7 @@ NS_ASSUME_NONNULL_BEGIN /// asynchronously on the main queue. - (void)addScopes:(NSArray *)scopes presentingWindow:(NSWindow *)presentingWindow - completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth, + completion:(nullable void (^)(GIDSignInResult *_Nullable signInResult, NSError *_Nullable error))completion; #endif diff --git a/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h b/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h index 3542ed7d..9ea59812 100644 --- a/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h +++ b/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h @@ -25,7 +25,7 @@ @class GIDConfiguration; @class GIDGoogleUser; -@class GIDUserAuth; +@class GIDSignInResult; NS_ASSUME_NONNULL_BEGIN @@ -117,8 +117,9 @@ typedef NS_ERROR_ENUM(kGIDSignInErrorDomain, GIDSignInErrorCode) { /// @param completion The optional block that is called on completion. This block will /// be called asynchronously on the main queue. - (void)signInWithPresentingViewController:(UIViewController *)presentingViewController - completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth, - NSError *_Nullable error))completion + completion: + (nullable void (^)(GIDSignInResult *_Nullable signInResult, + NSError *_Nullable error))completion NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions."); /// Starts an interactive sign-in flow on iOS using the provided hint. @@ -137,8 +138,9 @@ typedef NS_ERROR_ENUM(kGIDSignInErrorDomain, GIDSignInErrorCode) { /// be called asynchronously on the main queue. - (void)signInWithPresentingViewController:(UIViewController *)presentingViewController hint:(nullable NSString *)hint - completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth, - NSError *_Nullable error))completion + completion: + (nullable void (^)(GIDSignInResult *_Nullable signInResult, + NSError *_Nullable error))completion NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions."); /// Starts an interactive sign-in flow on iOS using the provided hint and additional scopes. @@ -155,12 +157,12 @@ typedef NS_ERROR_ENUM(kGIDSignInErrorDomain, GIDSignInErrorCode) { /// @param additionalScopes An optional array of scopes to request in addition to the basic profile scopes. /// @param completion The optional block that is called on completion. This block will /// be called asynchronously on the main queue. - - (void)signInWithPresentingViewController:(UIViewController *)presentingViewController hint:(nullable NSString *)hint additionalScopes:(nullable NSArray *)additionalScopes - completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth, - NSError *_Nullable error))completion + completion: + (nullable void (^)(GIDSignInResult *_Nullable signInResult, + NSError *_Nullable error))completion NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions."); #elif TARGET_OS_OSX @@ -176,7 +178,7 @@ typedef NS_ERROR_ENUM(kGIDSignInErrorDomain, GIDSignInErrorCode) { /// @param completion The optional block that is called on completion. This block will /// be called asynchronously on the main queue. - (void)signInWithPresentingWindow:(NSWindow *)presentingWindow - completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth, + completion:(nullable void (^)(GIDSignInResult *_Nullable signInResult, NSError *_Nullable error))completion; /// Starts an interactive sign-in flow on macOS using the provided hint. @@ -193,7 +195,7 @@ typedef NS_ERROR_ENUM(kGIDSignInErrorDomain, GIDSignInErrorCode) { /// be called asynchronously on the main queue. - (void)signInWithPresentingWindow:(NSWindow *)presentingWindow hint:(nullable NSString *)hint - completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth, + completion:(nullable void (^)(GIDSignInResult *_Nullable signInResult, NSError *_Nullable error))completion; /// Starts an interactive sign-in flow on macOS using the provided hint. @@ -212,7 +214,7 @@ typedef NS_ERROR_ENUM(kGIDSignInErrorDomain, GIDSignInErrorCode) { - (void)signInWithPresentingWindow:(NSWindow *)presentingWindow hint:(nullable NSString *)hint additionalScopes:(nullable NSArray *)additionalScopes - completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth, + completion:(nullable void (^)(GIDSignInResult *_Nullable signInResult, NSError *_Nullable error))completion; #endif diff --git a/GoogleSignIn/Sources/Public/GoogleSignIn/GIDUserAuth.h b/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignInResult.h similarity index 89% rename from GoogleSignIn/Sources/Public/GoogleSignIn/GIDUserAuth.h rename to GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignInResult.h index 6baeea09..3da9158b 100644 --- a/GoogleSignIn/Sources/Public/GoogleSignIn/GIDUserAuth.h +++ b/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignInResult.h @@ -20,8 +20,8 @@ NS_ASSUME_NONNULL_BEGIN -/// A helper object that contains the outcome of a successful signIn or addScopes flow. -@interface GIDUserAuth : NSObject +/// A helper object that contains the result of a successful signIn or addScopes flow. +@interface GIDSignInResult : NSObject /// The updated `GIDGoogleUser` instance for the user who just completed the flow. @property(nonatomic, readonly) GIDGoogleUser *user; diff --git a/GoogleSignIn/Sources/Public/GoogleSignIn/GoogleSignIn.h b/GoogleSignIn/Sources/Public/GoogleSignIn/GoogleSignIn.h index 1b9d1042..5923329d 100644 --- a/GoogleSignIn/Sources/Public/GoogleSignIn/GoogleSignIn.h +++ b/GoogleSignIn/Sources/Public/GoogleSignIn/GoogleSignIn.h @@ -20,7 +20,7 @@ #import "GIDProfileData.h" #import "GIDSignIn.h" #import "GIDToken.h" -#import "GIDUserAuth.h" +#import "GIDSignInResult.h" #if TARGET_OS_IOS || TARGET_OS_MACCATALYST #import "GIDSignInButton.h" #endif diff --git a/GoogleSignIn/Tests/Unit/GIDGoogleUserTest.m b/GoogleSignIn/Tests/Unit/GIDGoogleUserTest.m index b79d419b..3f42afd6 100644 --- a/GoogleSignIn/Tests/Unit/GIDGoogleUserTest.m +++ b/GoogleSignIn/Tests/Unit/GIDGoogleUserTest.m @@ -499,9 +499,9 @@ - (void)testAddScopes_failure_addScopesToPreviousUser { #elif TARGET_OS_OSX presentingWindow:[[NSWindow alloc] init] #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST - completion:^(GIDUserAuth *userAuth, NSError *error) { + completion:^(GIDSignInResult *signInResult, NSError *error) { [expectation fulfill]; - XCTAssertNil(userAuth); + XCTAssertNil(signInResult); XCTAssertEqual(error.code, kGIDSignInErrorCodeMismatchWithCurrentUser); }]; @@ -527,9 +527,9 @@ - (void)testAddScopes_failure_addScopesToPreviousUser_currentUserIsNull { #elif TARGET_OS_OSX presentingWindow:[[NSWindow alloc] init] #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST - completion:^(GIDUserAuth *userAuth, NSError *error) { + completion:^(GIDSignInResult *signInResult, NSError *error) { [expectation fulfill]; - XCTAssertNil(userAuth); + XCTAssertNil(signInResult); XCTAssertEqual(error.code, kGIDSignInErrorCodeMismatchWithCurrentUser); }]; diff --git a/GoogleSignIn/Tests/Unit/GIDSignInInternalOptionsTest.m b/GoogleSignIn/Tests/Unit/GIDSignInInternalOptionsTest.m index cc1d63d2..bcc48910 100644 --- a/GoogleSignIn/Tests/Unit/GIDSignInInternalOptionsTest.m +++ b/GoogleSignIn/Tests/Unit/GIDSignInInternalOptionsTest.m @@ -38,8 +38,8 @@ - (void)testDefaultOptions { #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST NSString *loginHint = @"login_hint"; - void (^completion)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error) = - ^(GIDUserAuth *_Nullable userAuth, NSError * _Nullable error) {}; + GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult, + NSError * _Nullable error) {}; GIDSignInInternalOptions *options = [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration #if TARGET_OS_IOS || TARGET_OS_MACCATALYST @@ -64,8 +64,8 @@ - (void)testDefaultOptions { } - (void)testSilentOptions { - void (^completion)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error) = - ^(GIDUserAuth *_Nullable userAuth, NSError * _Nullable error) {}; + GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult, + NSError * _Nullable error) {}; GIDSignInInternalOptions *options = [GIDSignInInternalOptions silentOptionsWithCompletion:completion]; XCTAssertFalse(options.interactive); XCTAssertFalse(options.continuation); diff --git a/GoogleSignIn/Tests/Unit/GIDSignInTest.m b/GoogleSignIn/Tests/Unit/GIDSignInTest.m index c42be2de..7a81ede6 100644 --- a/GoogleSignIn/Tests/Unit/GIDSignInTest.m +++ b/GoogleSignIn/Tests/Unit/GIDSignInTest.m @@ -235,7 +235,7 @@ @interface GIDSignInTest : XCTestCase { NSString *_hint; // The completion to be used when testing |GIDSignIn|. - GIDUserAuthCompletion _completion; + GIDSignInCompletion _completion; // The saved authorization request. OIDAuthorizationRequest *_savedAuthorizationRequest; @@ -334,10 +334,10 @@ - (void)setUp { _hint = nil; __weak GIDSignInTest *weakSelf = self; - _completion = ^(GIDUserAuth *_Nullable userAuth, NSError * _Nullable error) { + _completion = ^(GIDSignInResult *_Nullable signInResult, NSError * _Nullable error) { GIDSignInTest *strongSelf = weakSelf; - if (!userAuth) { - XCTAssertNotNil(error, @"should have an error if the userAuth is nil"); + if (!signInResult) { + XCTAssertNotNil(error, @"should have an error if the signInResult is nil"); } XCTAssertFalse(strongSelf->_completionCalled, @"callback already called"); strongSelf->_completionCalled = YES; @@ -1249,13 +1249,13 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow } } else { XCTestExpectation *expectation = [self expectationWithDescription:@"Callback called"]; - GIDUserAuthCompletion completion = - ^(GIDUserAuth *_Nullable userAuth, NSError * _Nullable error) { + GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult, + NSError * _Nullable error) { [expectation fulfill]; - if (userAuth) { - XCTAssertEqualObjects(userAuth.serverAuthCode, kServerAuthCode); + if (signInResult) { + XCTAssertEqualObjects(signInResult.serverAuthCode, kServerAuthCode); } else { - XCTAssertNotNil(error, @"Should have an error if the userAuth is nil"); + XCTAssertNotNil(error, @"Should have an error if the signInResult is nil"); } XCTAssertFalse(self->_completionCalled, @"callback already called"); self->_completionCalled = YES; diff --git a/Samples/ObjC/SignInSample/Source/SignInViewController.m b/Samples/ObjC/SignInSample/Source/SignInViewController.m index 8524bb26..4898fc8a 100644 --- a/Samples/ObjC/SignInSample/Source/SignInViewController.m +++ b/Samples/ObjC/SignInSample/Source/SignInViewController.m @@ -248,7 +248,7 @@ - (void)updateButtons { - (IBAction)signIn:(id)sender { [GIDSignIn.sharedInstance signInWithPresentingViewController:self - completion:^(GIDUserAuth *userAuth, + completion:^(GIDSignInResult *signInResult, NSError *error) { if (error) { self->_signInAuthStatus.text = @@ -283,7 +283,7 @@ - (IBAction)addScopes:(id)sender { GIDGoogleUser *currentUser = GIDSignIn.sharedInstance.currentUser; [currentUser addScopes:@[ @"https://www.googleapis.com/auth/user.birthday.read" ] presentingViewController:self - completion:^(GIDUserAuth *_Nullable userAuth, + completion:^(GIDSignInResult *_Nullable signInResult, NSError *_Nullable error) { if (error) { self->_signInAuthStatus.text = [NSString stringWithFormat:@"Status: Failed to add scopes: %@", diff --git a/Samples/Swift/DaysUntilBirthday/Shared/Services/GoogleSignInAuthenticator.swift b/Samples/Swift/DaysUntilBirthday/Shared/Services/GoogleSignInAuthenticator.swift index 93c29a6f..deacb35b 100644 --- a/Samples/Swift/DaysUntilBirthday/Shared/Services/GoogleSignInAuthenticator.swift +++ b/Samples/Swift/DaysUntilBirthday/Shared/Services/GoogleSignInAuthenticator.swift @@ -36,12 +36,12 @@ final class GoogleSignInAuthenticator: ObservableObject { return } - GIDSignIn.sharedInstance.signIn(withPresenting: rootViewController) { userAuth, error in - guard let userAuth = userAuth else { + GIDSignIn.sharedInstance.signIn(withPresenting: rootViewController) { signInResult, error in + guard let signInResult = signInResult else { print("Error! \(String(describing: error))") return } - self.authViewModel.state = .signedIn(userAuth.user) + self.authViewModel.state = .signedIn(signInResult.user) } #elseif os(macOS) @@ -50,12 +50,12 @@ final class GoogleSignInAuthenticator: ObservableObject { return } - GIDSignIn.sharedInstance.signIn(withPresenting: presentingWindow) { userAuth, error in - guard let userAuth = userAuth else { + GIDSignIn.sharedInstance.signIn(withPresenting: presentingWindow) { signInResult, error in + guard let signInResult = signInResult else { print("Error! \(String(describing: error))") return } - self.authViewModel.state = .signedIn(userAuth.user) + self.authViewModel.state = .signedIn(signInResult.user) } #endif } @@ -93,14 +93,14 @@ final class GoogleSignInAuthenticator: ObservableObject { } currentUser.addScopes([BirthdayLoader.birthdayReadScope], - presenting: rootViewController) { userAuth, error in + presenting: rootViewController) { signInResult, error in if let error = error { print("Found error while adding birthday read scope: \(error).") return } - guard let userAuth = userAuth else { return } - self.authViewModel.state = .signedIn(userAuth.user) + guard let signInResult = signInResult else { return } + self.authViewModel.state = .signedIn(signInResult.user) completion() } @@ -110,14 +110,14 @@ final class GoogleSignInAuthenticator: ObservableObject { } currentUser.addScopes([BirthdayLoader.birthdayReadScope], - presenting: presentingWindow) { userAuth, error in + presenting: presentingWindow) { signInResult, error in if let error = error { print("Found error while adding birthday read scope: \(error).") return } - guard let userAuth = userAuth else { return } - self.authViewModel.state = .signedIn(userAuth.user) + guard let signInResult = signInResult else { return } + self.authViewModel.state = .signedIn(signInResult.user) completion() }