Skip to content

Add login_hint to FUIOAuth. #663

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

Merged
merged 1 commit into from
Apr 4, 2019
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
24 changes: 4 additions & 20 deletions OAuth/FirebaseOAuthUI/FUIOAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,28 +58,9 @@ NS_ASSUME_NONNULL_BEGIN
iconImage:(UIImage *)iconImage
scopes:(nullable NSArray<NSString *> *)scopes
customParameters:(nullable NSDictionary<NSString *, NSString*> *)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<NSString *> *)scopes
customParameters:(nullable NSDictionary<NSString *, NSString*> *)customParameters;

@end

NS_ASSUME_NONNULL_END
39 changes: 19 additions & 20 deletions OAuth/FirebaseOAuthUI/FUIOAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ @interface FUIOAuth ()
*/
@property(nonatomic, copy, nullable) NSDictionary<NSString *, NSString*> *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.
*/
Expand All @@ -101,7 +106,8 @@ - (instancetype)initWithAuthUI:(FUIAuth *)authUI
buttonColor:(UIColor *)buttonColor
iconImage:(UIImage *)iconImage
scopes:(nullable NSArray<NSString *> *)scopes
customParameters:(nullable NSDictionary<NSString *, NSString*> *)customParameters {
customParameters:(nullable NSDictionary<NSString *, NSString*> *)customParameters
loginHintKey:(nullable NSString *)loginHintKey {
if (self = [super init]) {
_authUI = authUI;
_providerID = providerID;
Expand All @@ -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<NSString *> *)scopes
customParameters:(nullable NSDictionary<NSString *, NSString*> *)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:
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ + (NSArray *)getListOfIDPs:(NSArray<NSIndexPath *> *)selectedRows
buttonColor:buttonColor
iconImage:[UIImage imageWithContentsOfFile:iconPath]
scopes:@[@"user.readwrite"]
customParameters:@{@"prompt" : @"consent"}];
customParameters:@{@"prompt" : @"consent"}
loginHintKey:@"login_hint"];
}
break;
default:
Expand Down