Просмотр исходного кода

Implement GIDVerifyAccountDetail interface methods to start interactive flow. (#398)

Brianna Morales 1 год назад
Родитель
Сommit
e4f342537d

+ 35 - 0
GoogleSignIn/Sources/GIDConfiguration.m

@@ -26,6 +26,12 @@ static NSString *const kHostedDomainKey = @"hostedDomain";
 // 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";
+static NSString *const kConfigServerClientIDKey = @"GIDServerClientID";
+static NSString *const kConfigHostedDomainKey = @"GIDHostedDomain";
+static NSString *const kConfigOpenIDRealmKey = @"GIDOpenIDRealm";
+
 NS_ASSUME_NONNULL_BEGIN
 
 @implementation GIDConfiguration
@@ -59,6 +65,35 @@ NS_ASSUME_NONNULL_BEGIN
   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:

+ 1 - 39
GoogleSignIn/Sources/GIDSignIn.m

@@ -135,12 +135,6 @@ static NSString *const kHostedDomainParameter = @"hd";
 // 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
 
@@ -458,7 +452,7 @@ static NSString *const kConfigOpenIDRealmKey = @"GIDOpenIDRealm";
 
     // 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.
@@ -1019,38 +1013,6 @@ static NSString *const kConfigOpenIDRealmKey = @"GIDOpenIDRealm";
             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

+ 1 - 1
GoogleSignIn/Sources/GIDSignInInternalOptions.m

@@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
   GIDSignInInternalOptions *options = [[GIDSignInInternalOptions alloc] init];
   if (options) {
     options->_interactive = YES;
-    options->_continuation = NO;
+    options->_continuation = NO; // Not relevant to VwG flow.
     options->_addScopesFlow = addScopesFlow;
     options->_configuration = configuration;
     options->_presentingViewController = presentingViewController;

+ 24 - 9
GoogleSignIn/Sources/GIDVerifyAccountDetail/Implementations/GIDVerifyAccountDetail.m

@@ -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
@@ -27,7 +31,10 @@
     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
@@ -35,16 +42,24 @@
                         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

+ 5 - 0
GoogleSignIn/Sources/Public/GoogleSignIn/GIDConfiguration.h

@@ -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

+ 4 - 18
GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifyAccountDetail.h

@@ -28,6 +28,7 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
+@class GIDConfiguration;
 @class GIDVerifiableAccountDetail;
 @class GIDVerifiedAccountDetailResult;
 
@@ -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
@@ -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