Sfoglia il codice sorgente

Implement -signInWithConfiguration:presentingViewController:hint:callback:

Peter Andrews 4 anni fa
parent
commit
2ba99237a4

+ 1 - 13
GoogleSignIn/Sources/GIDConfiguration.m

@@ -20,9 +20,6 @@ static NSString *const kClientIDKey = @"clientID";
 // The key for the serverClientID property to be used with NSSecureCoding.
 static NSString *const kServerClientIDKey = @"serverClientID";
 
-// The key for the loginHint property to be used with NSSecureCoding.
-static NSString *const kLoginHintKey = @"loginHint";
-
 // The key for the hostedDomain property to be used with NSSecureCoding.
 static NSString *const kHostedDomainKey = @"hostedDomain";
 
@@ -36,7 +33,6 @@ NS_ASSUME_NONNULL_BEGIN
 - (instancetype)initWithClientID:(NSString *)clientID {
   return [self initWithClientID:clientID
                  serverClientID:nil
-                      loginHint:nil
                    hostedDomain:nil
                     openIDRealm:nil];
 }
@@ -45,21 +41,18 @@ NS_ASSUME_NONNULL_BEGIN
                   serverClientID:(nullable NSString *)serverClientID {
   return [self initWithClientID:clientID
                  serverClientID:serverClientID
-                      loginHint:nil
                    hostedDomain:nil
                     openIDRealm:nil];
 }
 
 - (instancetype)initWithClientID:(NSString *)clientID
                   serverClientID:(nullable NSString *)serverClientID
-                       loginHint:(nullable NSString *)loginHint
                     hostedDomain:(nullable NSString *)hostedDomain
                      openIDRealm:(nullable NSString *)openIDRealm {
   self = [super init];
   if (self) {
     _clientID = [clientID copy];
     _serverClientID = [serverClientID copy];
-    _loginHint = [loginHint copy];
     _hostedDomain = [hostedDomain copy];
     _openIDRealm = [openIDRealm copy];
   }
@@ -69,13 +62,11 @@ NS_ASSUME_NONNULL_BEGIN
 // Extend NSObject's default description for easier debugging.
 - (NSString *)description {
   return [NSString stringWithFormat:
-      @"<%@: %p, clientID: %@, serverClientID: %@, loginHint: %@, hostedDomain: %@, "
-          "openIDRealm: %@>",
+      @"<%@: %p, clientID: %@, serverClientID: %@, hostedDomain: %@, openIDRealm: %@>",
       NSStringFromClass([self class]),
       self,
       _clientID,
       _serverClientID,
-      _loginHint,
       _hostedDomain,
       _openIDRealm];
 }
@@ -96,7 +87,6 @@ NS_ASSUME_NONNULL_BEGIN
 - (nullable instancetype)initWithCoder:(NSCoder *)coder {
   NSString *clientID = [coder decodeObjectOfClass:[NSString class] forKey:kClientIDKey];
   NSString *serverClientID = [coder decodeObjectOfClass:[NSString class] forKey:kServerClientIDKey];
-  NSString *loginHint = [coder decodeObjectOfClass:[NSString class] forKey:kLoginHintKey];
   NSString *hostedDomain = [coder decodeObjectOfClass:[NSString class] forKey:kHostedDomainKey];
   NSString *openIDRealm = [coder decodeObjectOfClass:[NSString class] forKey:kOpenIDRealmKey];
 
@@ -107,7 +97,6 @@ NS_ASSUME_NONNULL_BEGIN
 
   return [self initWithClientID:clientID
                  serverClientID:serverClientID
-                      loginHint:loginHint
                    hostedDomain:hostedDomain
                     openIDRealm:openIDRealm];
 }
@@ -115,7 +104,6 @@ NS_ASSUME_NONNULL_BEGIN
 - (void)encodeWithCoder:(NSCoder *)coder {
   [coder encodeObject:_clientID forKey:kClientIDKey];
   [coder encodeObject:_serverClientID forKey:kServerClientIDKey];
-  [coder encodeObject:_loginHint forKey:kLoginHintKey];
   [coder encodeObject:_hostedDomain forKey:kHostedDomainKey];
   [coder encodeObject:_openIDRealm forKey:kOpenIDRealmKey];
 }

+ 15 - 3
GoogleSignIn/Sources/GIDSignIn.m

@@ -191,14 +191,26 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
 
 - (void)signInWithConfiguration:(GIDConfiguration *)configuration
        presentingViewController:(UIViewController *)presentingViewController
+                           hint:(nullable NSString *)hint
                        callback:(GIDSignInCallback)callback {
   GIDSignInInternalOptions *options =
       [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
                                        presentingViewController:presentingViewController
+                                                      loginHint:hint
                                                        callback:callback];
   [self signInWithOptions:options];
 }
 
+- (void)signInWithConfiguration:(GIDConfiguration *)configuration
+       presentingViewController:(UIViewController *)presentingViewController
+                       callback:(GIDSignInCallback)callback {
+  [self signInWithConfiguration:configuration
+       presentingViewController:presentingViewController
+                           hint:nil
+                       callback:callback];
+}
+
+
 - (void)addScopes:(NSArray<NSString *> *)scopes
     presentingViewController:(UIViewController *)presentingViewController
                     callback:(GIDSignInCallback)callback {
@@ -215,12 +227,12 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
   GIDConfiguration *configuration =
       [[GIDConfiguration alloc] initWithClientID:self.currentUser.authentication.clientID
                                   serverClientID:self.currentUser.serverClientID
-                                       loginHint:self.currentUser.profile.email
                                     hostedDomain:self.currentUser.hostedDomain
                                      openIDRealm:self.currentUser.openIDRealm];
   GIDSignInInternalOptions *options =
       [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
                                        presentingViewController:presentingViewController
+                                                      loginHint:self.currentUser.profile.email
                                                        callback:callback];
 
   NSSet<NSString *> *requestedScopes = [NSSet setWithArray:scopes];
@@ -395,8 +407,8 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
   if (options.configuration.serverClientID) {
     additionalParameters[kAudienceParameter] = options.configuration.serverClientID;
   }
-  if (options.configuration.loginHint) {
-    additionalParameters[@"login_hint"] = options.configuration.loginHint;
+  if (options.loginHint) {
+    additionalParameters[@"login_hint"] = options.loginHint;
   }
   if (options.configuration.hostedDomain) {
     additionalParameters[@"hd"] = options.configuration.hostedDomain;

+ 4 - 0
GoogleSignIn/Sources/GIDSignInInternalOptions.h

@@ -44,9 +44,13 @@ NS_ASSUME_NONNULL_BEGIN
 /// The scopes to be used during the flow.
 @property(nonatomic, copy, nullable) NSArray<NSString *> *scopes;
 
+/// The login hint to be used during the flow.
+@property(nonatomic, copy, nullable) NSString *loginHint;
+
 /// Creates the default options.
 + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
                        presentingViewController:(nullable UIViewController *)presentingViewController
+                                      loginHint:(nullable NSString *)loginHint
                                        callback:(GIDSignInCallback)callback;
 
 /// Creates the options to sign in silently.

+ 5 - 0
GoogleSignIn/Sources/GIDSignInInternalOptions.m

@@ -22,6 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
                        presentingViewController:(nullable UIViewController *)presentingViewController
+                                      loginHint:(nullable NSString *)loginHint
                                        callback:(GIDSignInCallback)callback {
   GIDSignInInternalOptions *options = [[GIDSignInInternalOptions alloc] init];
   if (options) {
@@ -29,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
     options->_continuation = NO;
     options->_configuration = configuration;
     options->_presentingViewController = presentingViewController;
+    options->_loginHint = loginHint;
     options->_callback = callback;
     options->_scopes = [GIDScopes scopesWithBasicProfile:@[]];
   }
@@ -38,6 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
 + (instancetype)silentOptionsWithCallback:(GIDSignInCallback)callback {
   GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:nil
                                                    presentingViewController:nil
+                                                                  loginHint:nil
                                                                    callback:callback];
   if (options) {
     options->_interactive = NO;
@@ -49,6 +52,7 @@ NS_ASSUME_NONNULL_BEGIN
                         extraParams:(NSDictionary *)extraParams {
   GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:nil
                                                    presentingViewController:nil
+                                                                  loginHint:nil
                                                                    callback:callback];
   if (options) {
     options->_extraParams = [extraParams copy];
@@ -64,6 +68,7 @@ NS_ASSUME_NONNULL_BEGIN
     options->_continuation = continuation;
     options->_configuration = _configuration;
     options->_presentingViewController = _presentingViewController;
+    options->_loginHint = _loginHint;
     options->_callback = _callback;
     options->_scopes = _scopes;
     options->_extraParams = [extraParams copy];

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

@@ -29,10 +29,6 @@ NS_ASSUME_NONNULL_BEGIN
 /// https://developers.google.com/identity/sign-in/ios/backend-auth
 @property(nonatomic, readonly, nullable) NSString *serverClientID;
 
-/// The login hint to the authorization server, for example the user's ID, or email address,
-/// to be prefilled if possible.
-@property(nonatomic, readonly, nullable) NSString *loginHint;
-
 /// The Google Apps domain to which users must belong to sign in.  To verify, check
 /// `GIDGoogleUser`'s `hostedDomain` property.
 @property(nonatomic, readonly, nullable) NSString *hostedDomain;
@@ -62,13 +58,11 @@ NS_ASSUME_NONNULL_BEGIN
 ///
 /// @param clientID The client ID of the app.
 /// @param serverClientID The server's client ID.
-/// @param loginHint The login hint to be used.
 /// @param hostedDomain The Google Apps domain to be used.
 /// @param openIDRealm The OpenID realm to be used.
 /// @return An initilized `GIDConfiguration` instance.
 - (instancetype)initWithClientID:(NSString *)clientID
                   serverClientID:(nullable NSString *)serverClientID
-                       loginHint:(nullable NSString *)loginHint
                     hostedDomain:(nullable NSString *)hostedDomain
                      openIDRealm:(nullable NSString *)openIDRealm NS_DESIGNATED_INITIALIZER;
 

+ 19 - 1
GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h

@@ -91,7 +91,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
 /// The callback will be called at the end of this process.  Any saved sign-in state will be
 /// replaced by the result of this flow.  Note that this method should not be called when the app is
 /// starting up, (e.g in `application:didFinishLaunchingWithOptions:`); instead use the
-/// `restorePreviousSignInWithCallback` method to restore a previous sign-in.
+/// `restorePreviousSignInWithCallback:` method to restore a previous sign-in.
 ///
 /// @param configuration The configuration properties to be used for this flow.
 /// @param presentingViewController The view controller used to present `SFSafariViewContoller` on
@@ -101,6 +101,24 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
        presentingViewController:(UIViewController *)presentingViewController
                        callback:(GIDSignInCallback)callback;
 
+/// Starts an interactive sign-in flow using the provided configuration and a login hint.
+///
+/// The callback will be called at the end of this process.  Any saved sign-in state will be
+/// replaced by the result of this flow.  Note that this method should not be called when the app is
+/// starting up, (e.g in `application:didFinishLaunchingWithOptions:`); instead use the
+/// `restorePreviousSignInWithCallback:` method to restore a previous sign-in.
+///
+/// @param configuration The configuration properties to be used for this flow.
+/// @param presentingViewController The view controller used to present `SFSafariViewContoller` on
+///     iOS 9 and 10.
+/// @param hint An optional hint for the authorization server, for example the user's ID or email
+///     address, to be prefilled if possible.
+/// @param callback The `GIDSignInCallback` block that is called on completion.
+- (void)signInWithConfiguration:(GIDConfiguration *)configuration
+       presentingViewController:(UIViewController *)presentingViewController
+                           hint:(nullable NSString *)hint
+                       callback:(GIDSignInCallback)callback;
+
 /// Starts an interactive consent flow to add scopes to the current user's grants.
 ///
 /// @param scopes The scopes to ask the user to consent to.