Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement methods to create the default options for the verify flow. #387

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
20 changes: 20 additions & 0 deletions GoogleSignIn/Sources/GIDSignInInternalOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

@class GIDConfiguration;
@class GIDSignInResult;
@class GIDVerifiableAccountDetail;
mdmathias marked this conversation as resolved.
Show resolved Hide resolved

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -41,6 +42,9 @@ NS_ASSUME_NONNULL_BEGIN
/// Whether the sign-in is an addScopes flow. NO means it is a sign in flow.
@property(nonatomic, readonly) BOOL addScopesFlow;

/// The user account details this flow will verify
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
@property(nonatomic, copy, nullable, readonly) NSArray<GIDVerifiableAccountDetail *> *accountDetailsToVerify;
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved

/// The extra parameters used in the sign-in URL.
@property(nonatomic, readonly, nullable) NSDictionary *extraParams;

Expand All @@ -58,6 +62,9 @@ NS_ASSUME_NONNULL_BEGIN
/// The completion block to be called at the completion of the flow.
@property(nonatomic, readonly, nullable) GIDSignInCompletion completion;

/// The completion block to be called at the completion of the verify flow.
@property(nonatomic, readonly, nullable) GIDVerifyCompletion verifyCompletion;

/// The scopes to be used during the flow.
@property(nonatomic, copy, nullable) NSArray<NSString *> *scopes;

Expand All @@ -79,6 +86,19 @@ NS_ASSUME_NONNULL_BEGIN
scopes:(nullable NSArray *)scopes
completion:(nullable GIDSignInCompletion)completion;

+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
presentingViewController:(nullable UIViewController *)presentingViewController
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
verifyCompletion:(nullable GIDVerifyCompletion)completion;

+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
presentingViewController:(nullable UIViewController *)presentingViewController
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
accountDetailsToVerify:(nullable NSArray *)accountDetailsToVerify
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
verifyCompletion:(nullable GIDVerifyCompletion)completion;

#elif TARGET_OS_OSX
+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
presentingWindow:(nullable NSWindow *)presentingWindow
Expand Down
37 changes: 37 additions & 0 deletions GoogleSignIn/Sources/GIDSignInInternalOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,43 @@
NS_ASSUME_NONNULL_BEGIN

@implementation GIDSignInInternalOptions
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
presentingViewController:(nullable UIViewController *)presentingViewController
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
verifyCompletion:(nullable GIDVerifyCompletion)completion{
GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:configuration
presentingViewController:presentingViewController
loginHint:loginHint
addScopesFlow:addScopesFlow
accountDetailsToVerify:@[]
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
verifyCompletion:completion];
return options;
}

+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
presentingViewController:(nullable UIViewController *)presentingViewController
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
accountDetailsToVerify:(nullable NSArray *)accountDetailsToVerify
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
verifyCompletion:(nullable GIDVerifyCompletion)completion{
GIDSignInInternalOptions *options = [[GIDSignInInternalOptions alloc] init];
if (options) {
options->_interactive = YES;
options->_continuation = NO;
options->_addScopesFlow = addScopesFlow;
options->_configuration = configuration;
options->_presentingViewController = presentingViewController;
options->_loginHint = loginHint;
options->_accountDetailsToVerify = accountDetailsToVerify;
options->_verifyCompletion = completion;
}
return options;
}

#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST

#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
presentingViewController:(nullable UIViewController *)presentingViewController
Expand Down
6 changes: 6 additions & 0 deletions GoogleSignIn/Sources/GIDSignIn_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ NS_ASSUME_NONNULL_BEGIN
@class GIDGoogleUser;
@class GIDSignInInternalOptions;
@class GTMKeychainStore;
@class GIDVerifiedAccountDetailResult;

/// 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 a `GIDVerifiedAccountDetailResult` on success or an
/// error if the operation was unsuccessful.
typedef void (^GIDVerifyCompletion)(GIDVerifiedAccountDetailResult *_Nullable verifiedResult,
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
NSError *_Nullable error);

/// Represents a completion block that takes an error if the operation was unsuccessful.
typedef void (^GIDDisconnectCompletion)(NSError *_Nullable error);

Expand Down
26 changes: 26 additions & 0 deletions GoogleSignIn/Tests/Unit/GIDSignInInternalOptionsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@ @interface GIDSignInInternalOptionsTest : XCTestCase

@implementation GIDSignInInternalOptionsTest

- (void)testDefaultOptionsForVerificationFlow {
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
id configuration = OCMStrictClassMock([GIDConfiguration class]);
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
id presentingViewController = OCMStrictClassMock([UIViewController class]);
NSString *loginHint = @"login_hint";

GIDVerifyCompletion completion = ^(GIDVerifiedAccountDetailResult *_Nullable verifiedResult,
NSError * _Nullable error) {};
GIDSignInInternalOptions *options =
[GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
presentingViewController:presentingViewController
loginHint:loginHint
addScopesFlow:NO
verifyCompletion:completion];
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved

XCTAssertTrue(options.interactive);
XCTAssertFalse(options.continuation);
XCTAssertFalse(options.addScopesFlow);
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
XCTAssertNil(options.extraParams);
XCTAssertEqual(options.accountDetailsToVerify, @[]);
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved

OCMVerifyAll(configuration);
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
OCMVerifyAll(presentingViewController);
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
}

- (void)testDefaultOptions {
id configuration = OCMStrictClassMock([GIDConfiguration class]);
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
Expand Down
Loading