From 2d5e551dd41b88e94d5d2b3647d9f9b1cf6c6a59 Mon Sep 17 00:00:00 2001 From: Yue Wang Date: Wed, 3 Apr 2019 16:49:32 -0700 Subject: [PATCH] Add login_hint to FUIOAuth. --- OAuth/FirebaseOAuthUI/FUIOAuth.h | 24 ++---------- OAuth/FirebaseOAuthUI/FUIOAuth.m | 39 +++++++++---------- .../Samples/Auth/FUIAuthViewController.m | 3 +- 3 files changed, 25 insertions(+), 41 deletions(-) diff --git a/OAuth/FirebaseOAuthUI/FUIOAuth.h b/OAuth/FirebaseOAuthUI/FUIOAuth.h index aa992ee0229..417f1912065 100644 --- a/OAuth/FirebaseOAuthUI/FUIOAuth.h +++ b/OAuth/FirebaseOAuthUI/FUIOAuth.h @@ -46,6 +46,9 @@ NS_ASSUME_NONNULL_BEGIN @param iconImage The icon image of the provider. @param scopes Array used to configure the OAuth scopes. @param customParameters Dictionary used to configure the OAuth custom parameters. + @param loginHintKey The key of the custom parameter, with which the login hint can be passed to + the IdP. + */ - (instancetype)initWithAuthUI:(FUIAuth *)authUI providerID:(NSString *)providerID @@ -55,28 +58,9 @@ NS_ASSUME_NONNULL_BEGIN iconImage:(UIImage *)iconImage scopes:(nullable NSArray *)scopes customParameters:(nullable NSDictionary *)customParameters + loginHintKey:(nullable NSString *)loginHintKey NS_DESIGNATED_INITIALIZER; -/** @fn providerID:buttonLabelText:buttonColor:iconImage:scopes:customParameters: - @brief Initialize the class instance with the default AuthUI. - - @param providerID The unique identifier for the provider. - @param buttonLabelText The text label for the sign in button. - @param shortName A short display name for the provider. - @param buttonColor The background color that should be used for the sign in button of the - provider. - @param iconImage The icon image of the provider. - @param scopes Array used to configure the OAuth scopes. - @param customParameters Dictionary used to configure the OAuth custom parameters. - */ -- (instancetype)initWithProviderID:(NSString *)providerID - buttonLabelText:(NSString *)buttonLabelText - shortName:(NSString *)shortName - buttonColor:(UIColor *)buttonColor - iconImage:(UIImage *)iconImage - scopes:(nullable NSArray *)scopes - customParameters:(nullable NSDictionary *)customParameters; - @end NS_ASSUME_NONNULL_END diff --git a/OAuth/FirebaseOAuthUI/FUIOAuth.m b/OAuth/FirebaseOAuthUI/FUIOAuth.m index 6b04a9cdaef..66f6a06784b 100644 --- a/OAuth/FirebaseOAuthUI/FUIOAuth.m +++ b/OAuth/FirebaseOAuthUI/FUIOAuth.m @@ -85,6 +85,11 @@ @interface FUIOAuth () */ @property(nonatomic, copy, nullable) NSDictionary *customParameters; +/** @property loginHintKey + @brief The key of the custom parameter, with which the login hint can be passed to the IdP. + */ +@property(nonatomic, copy, nullable) NSString *loginHintKey; + /** @property provider @brief The OAuth provider that does the actual sign in. */ @@ -101,7 +106,8 @@ - (instancetype)initWithAuthUI:(FUIAuth *)authUI buttonColor:(UIColor *)buttonColor iconImage:(UIImage *)iconImage scopes:(nullable NSArray *)scopes - customParameters:(nullable NSDictionary *)customParameters { + customParameters:(nullable NSDictionary *)customParameters + loginHintKey:(nullable NSString *)loginHintKey { if (self = [super init]) { _authUI = authUI; _providerID = providerID; @@ -112,29 +118,11 @@ - (instancetype)initWithAuthUI:(FUIAuth *)authUI _scopes = scopes; _customParameters = customParameters; _provider = [FIROAuthProvider providerWithProviderID:self.providerID]; - _provider.customParameters = self.customParameters; - _provider.scopes = self.scopes; + _loginHintKey = loginHintKey; } return self; } -- (instancetype)initWithProviderID:(NSString *)providerID - buttonLabelText:(NSString *)buttonLabelText - shortName:(NSString *)shortName - buttonColor:(UIColor *)buttonColor - iconImage:(UIImage *)iconImage - scopes:(nullable NSArray *)scopes - customParameters:(nullable NSDictionary *)customParameters { - return [self initWithAuthUI:[FUIAuth defaultAuthUI] - providerID:providerID - buttonLabelText:buttonLabelText - shortName:shortName - buttonColor:buttonColor - iconImage:iconImage - scopes:scopes - customParameters:customParameters]; -} - #pragma mark - FUIAuthProvider /** @fn accessToken: @@ -171,6 +159,17 @@ - (void)signInWithDefaultValue:(nullable NSString *)defaultValue completion:(nullable FUIAuthProviderSignInCompletionBlock)completion { self.presentingViewController = presentingViewController; + FIROAuthProvider *provider = self.provider; + provider.scopes = self.scopes; + NSMutableDictionary *customParameters = [NSMutableDictionary dictionary]; + if (self.customParameters.count) { + [customParameters addEntriesFromDictionary:self.customParameters]; + } + if (self.loginHintKey.length && defaultValue.length) { + customParameters[self.loginHintKey] = defaultValue; + } + provider.customParameters = [customParameters copy]; + [self.provider getCredentialWithUIDelegate:nil completion:^(FIRAuthCredential *_Nullable credential, NSError *_Nullable error) { diff --git a/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUIAuthViewController.m b/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUIAuthViewController.m index 6500261d7df..e7b8f21d0a3 100644 --- a/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUIAuthViewController.m +++ b/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUIAuthViewController.m @@ -429,7 +429,8 @@ + (NSArray *)getListOfIDPs:(NSArray *)selectedRows buttonColor:buttonColor iconImage:[UIImage imageWithContentsOfFile:iconPath] scopes:@[@"user.readwrite"] - customParameters:@{@"prompt" : @"consent"}]; + customParameters:@{@"prompt" : @"consent"} + loginHintKey:@"login_hint"]; } break; default: