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 GIDVerifyAccountDetail interface methods to start interactive flow. #398

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
35 changes: 35 additions & 0 deletions GoogleSignIn/Sources/GIDConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
// The key for the openIDRealm property to be used with NSSecureCoding.
static NSString *const kOpenIDRealmKey = @"openIDRealm";

// Info.plist config keys
static NSString *const kConfigClientIDKey = @"GIDClientID";
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
static NSString *const kConfigServerClientIDKey = @"GIDServerClientID";
static NSString *const kConfigHostedDomainKey = @"GIDHostedDomain";
static NSString *const kConfigOpenIDRealmKey = @"GIDOpenIDRealm";

NS_ASSUME_NONNULL_BEGIN

@implementation GIDConfiguration
Expand Down Expand Up @@ -59,6 +65,35 @@ - (instancetype)initWithClientID:(NSString *)clientID
return self;
}

// Try to retrieve a configuration value from an |NSBundle|'s Info.plist for a given key.
+ (nullable NSString *)configValueFromBundle:(NSBundle *)bundle forKey:(NSString *)key {
NSString *value;
id configValue = [bundle objectForInfoDictionaryKey:key];
if ([configValue isKindOfClass:[NSString class]]) {
value = configValue;
}
return value;
}

+ (nullable instancetype)configurationFromBundle:(NSBundle *)bundle {
// Retrieve any valid config parameters from the bundle's Info.plist.
NSString *clientID = [self configValueFromBundle:bundle forKey:kConfigClientIDKey];
NSString *serverClientID = [self configValueFromBundle:bundle
forKey:kConfigServerClientIDKey];
NSString *hostedDomain = [self configValueFromBundle:bundle forKey:kConfigHostedDomainKey];
NSString *openIDRealm = [self configValueFromBundle:bundle forKey:kConfigOpenIDRealmKey];

// If we have at least a client ID, try to construct a configuration.
if (clientID) {
return [[self alloc] initWithClientID:clientID
serverClientID:serverClientID
hostedDomain:hostedDomain
openIDRealm:openIDRealm];
}

return nil;
}

// Extend NSObject's default description for easier debugging.
- (NSString *)description {
return [NSString stringWithFormat:
Expand Down
40 changes: 1 addition & 39 deletions GoogleSignIn/Sources/GIDSignIn.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,6 @@
// Minimum time to expiration for a restored access token.
static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;

// Info.plist config keys
static NSString *const kConfigClientIDKey = @"GIDClientID";
static NSString *const kConfigServerClientIDKey = @"GIDServerClientID";
static NSString *const kConfigHostedDomainKey = @"GIDHostedDomain";
static NSString *const kConfigOpenIDRealmKey = @"GIDOpenIDRealm";

// The callback queue used for authentication flow.
@interface GIDAuthFlow : GIDCallbackQueue

Expand Down Expand Up @@ -458,7 +452,7 @@ - (instancetype)initWithKeychainStore:(GTMKeychainStore *)keychainStore {

// If we have a bundle, try to set the active configuration from the bundle's Info.plist.
if (bundle) {
_configuration = [GIDSignIn configurationFromBundle:bundle];
_configuration = [GIDConfiguration configurationFromBundle:bundle];
}

// Check to see if the 3P app is being run for the first time after a fresh install.
Expand Down Expand Up @@ -1019,38 +1013,6 @@ - (GIDProfileData *)profileDataWithIDToken:(OIDIDToken *)idToken {
imageURL:[NSURL URLWithString:idToken.claims[kBasicProfilePictureKey]]];
}

// Try to retrieve a configuration value from an |NSBundle|'s Info.plist for a given key.
+ (nullable NSString *)configValueFromBundle:(NSBundle *)bundle forKey:(NSString *)key {
NSString *value;
id configValue = [bundle objectForInfoDictionaryKey:key];
if ([configValue isKindOfClass:[NSString class]]) {
value = configValue;
}
return value;
}

// Try to generate a |GIDConfiguration| from an |NSBundle|'s Info.plist.
+ (nullable GIDConfiguration *)configurationFromBundle:(NSBundle *)bundle {
GIDConfiguration *configuration;

// Retrieve any valid config parameters from the bundle's Info.plist.
NSString *clientID = [GIDSignIn configValueFromBundle:bundle forKey:kConfigClientIDKey];
NSString *serverClientID = [GIDSignIn configValueFromBundle:bundle
forKey:kConfigServerClientIDKey];
NSString *hostedDomain = [GIDSignIn configValueFromBundle:bundle forKey:kConfigHostedDomainKey];
NSString *openIDRealm = [GIDSignIn configValueFromBundle:bundle forKey:kConfigOpenIDRealmKey];

// If we have at least a client ID, try to construct a configuration.
if (clientID) {
configuration = [[GIDConfiguration alloc] initWithClientID:clientID
serverClientID:serverClientID
hostedDomain:hostedDomain
openIDRealm:openIDRealm];
}

return configuration;
}

@end

NS_ASSUME_NONNULL_END
2 changes: 1 addition & 1 deletion GoogleSignIn/Sources/GIDSignInInternalOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)con
GIDSignInInternalOptions *options = [[GIDSignInInternalOptions alloc] init];
if (options) {
options->_interactive = YES;
options->_continuation = NO;
brnnmrls marked this conversation as resolved.
Show resolved Hide resolved
options->_continuation = NO; // Not relevant to VwG flow.
options->_addScopesFlow = addScopesFlow;
options->_configuration = configuration;
options->_presentingViewController = presentingViewController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifyAccountDetail.h"

#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDConfiguration.h"
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h"
#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiedAccountDetailResult.h"

#import "GoogleSignIn/Sources/GIDSignInInternalOptions.h"
#import "GoogleSignIn/Sources/GIDSignInCallbackSchemes.h"

#if TARGET_OS_IOS

@implementation GIDVerifyAccountDetail
Expand All @@ -27,24 +31,35 @@ - (void)verifyAccountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDet
presentingViewController:(UIViewController *)presentingViewController
completion:(nullable void (^)(GIDVerifiedAccountDetailResult *_Nullable verifyResult,
NSError *_Nullable error))completion {
// TODO(#383): Implement this method.
[self verifyAccountDetails:accountDetails
presentingViewController:presentingViewController
hint:nil
completion:completion];
}

- (void)verifyAccountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDetails
presentingViewController:(UIViewController *)presentingViewController
hint:(nullable NSString *)hint
completion:(nullable void (^)(GIDVerifiedAccountDetailResult *_Nullable verifyResult,
NSError *_Nullable error))completion {
// TODO(#383): Implement this method.
NSBundle *bundle = NSBundle.mainBundle;
if (bundle) {
_configuration = [GIDConfiguration configurationFromBundle:bundle];
}

GIDSignInInternalOptions *options =
[GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration
presentingViewController:presentingViewController
loginHint:hint
addScopesFlow:YES
accountDetailsToVerify:accountDetails
verifyCompletion:completion];

[self verifyAccountDetailsInteractivelyWithOptions:options];
}

- (void)verifyAccountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDetails
presentingViewController:(UIViewController *)presentingViewController
hint:(nullable NSString *)hint
additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
completion:(nullable void (^)(GIDVerifiedAccountDetailResult *_Nullable verifyResult,
NSError *_Nullable error))completion {
// TODO(#383): Implement this method.
- (void)verifyAccountDetailsInteractivelyWithOptions:(GIDSignInInternalOptions *)options {
// TODO(#397): Sanity checks and start the incremental authorization flow.
}

@end
Expand Down
5 changes: 5 additions & 0 deletions GoogleSignIn/Sources/Public/GoogleSignIn/GIDConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ NS_ASSUME_NONNULL_BEGIN
hostedDomain:(nullable NSString *)hostedDomain
openIDRealm:(nullable NSString *)openIDRealm NS_DESIGNATED_INITIALIZER;

/// Try to generate a |GIDConfiguration| from an |NSBundle|'s Info.plist.
///
/// @param bundle The bundle to generate a configuration value.
+ (nullable instancetype)configurationFromBundle:(NSBundle *)bundle;

@end

NS_ASSUME_NONNULL_END
22 changes: 4 additions & 18 deletions GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifyAccountDetail.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

NS_ASSUME_NONNULL_BEGIN

@class GIDConfiguration;
@class GIDVerifiableAccountDetail;
@class GIDVerifiedAccountDetailResult;

Expand All @@ -39,6 +40,9 @@ typedef void (^GIDVerifyCompletion)(GIDVerifiedAccountDetailResult *_Nullable ve
/// This class is used to verify a user's Google account details.
@interface GIDVerifyAccountDetail : NSObject

/// The active configuration for this instance of `GIDVerifyAccountDetail`.
@property(nonatomic, nullable) GIDConfiguration *configuration;

/// Starts an interactive verification flow.
///
/// The completion will be called at the end of this process. Any saved verification
Expand Down Expand Up @@ -68,24 +72,6 @@ typedef void (^GIDVerifyCompletion)(GIDVerifiedAccountDetailResult *_Nullable ve
completion:(nullable void (^)(GIDVerifiedAccountDetailResult *_Nullable verifyResult,
NSError *_Nullable error))completion;

/// Starts an interactive verification flow using the provided hint and additional scopes.
///
/// The completion will be called at the end of this process. Any saved verification
/// state will be replaced by the result of this flow.
///
/// @param accountDetails A list of verifiable account details.
/// @param presentingViewController The view controller used to present the flow.
/// @param hint An optional hint for the authorization server, for example the user's ID or email
/// address, to be prefilled if possible.
/// @param additionalScopes An optional array of scopes to request in addition to the basic profile scopes.
/// @param completion The optional block called asynchronously on the main queue upon completion.
- (void)verifyAccountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDetails
presentingViewController:(UIViewController *)presentingViewController
hint:(nullable NSString *)hint
additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
completion:(nullable void (^)(GIDVerifiedAccountDetailResult *_Nullable verifyResult,
NSError *_Nullable error))completion;

@end

NS_ASSUME_NONNULL_END
Expand Down
Loading