Skip to content

Commit dd89fc7

Browse files
Add login_hint to FUIOAuth. (#663)
1 parent f9ae217 commit dd89fc7

File tree

3 files changed

+25
-41
lines changed

3 files changed

+25
-41
lines changed

OAuth/FirebaseOAuthUI/FUIOAuth.h

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ NS_ASSUME_NONNULL_BEGIN
4646
@param iconImage The icon image of the provider.
4747
@param scopes Array used to configure the OAuth scopes.
4848
@param customParameters Dictionary used to configure the OAuth custom parameters.
49+
@param loginHintKey The key of the custom parameter, with which the login hint can be passed to
50+
the IdP.
51+
4952
*/
5053
- (instancetype)initWithAuthUI:(FUIAuth *)authUI
5154
providerID:(NSString *)providerID
@@ -55,28 +58,9 @@ NS_ASSUME_NONNULL_BEGIN
5558
iconImage:(UIImage *)iconImage
5659
scopes:(nullable NSArray<NSString *> *)scopes
5760
customParameters:(nullable NSDictionary<NSString *, NSString*> *)customParameters
61+
loginHintKey:(nullable NSString *)loginHintKey
5862
NS_DESIGNATED_INITIALIZER;
5963

60-
/** @fn providerID:buttonLabelText:buttonColor:iconImage:scopes:customParameters:
61-
@brief Initialize the class instance with the default AuthUI.
62-
63-
@param providerID The unique identifier for the provider.
64-
@param buttonLabelText The text label for the sign in button.
65-
@param shortName A short display name for the provider.
66-
@param buttonColor The background color that should be used for the sign in button of the
67-
provider.
68-
@param iconImage The icon image of the provider.
69-
@param scopes Array used to configure the OAuth scopes.
70-
@param customParameters Dictionary used to configure the OAuth custom parameters.
71-
*/
72-
- (instancetype)initWithProviderID:(NSString *)providerID
73-
buttonLabelText:(NSString *)buttonLabelText
74-
shortName:(NSString *)shortName
75-
buttonColor:(UIColor *)buttonColor
76-
iconImage:(UIImage *)iconImage
77-
scopes:(nullable NSArray<NSString *> *)scopes
78-
customParameters:(nullable NSDictionary<NSString *, NSString*> *)customParameters;
79-
8064
@end
8165

8266
NS_ASSUME_NONNULL_END

OAuth/FirebaseOAuthUI/FUIOAuth.m

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ @interface FUIOAuth ()
8585
*/
8686
@property(nonatomic, copy, nullable) NSDictionary<NSString *, NSString*> *customParameters;
8787

88+
/** @property loginHintKey
89+
@brief The key of the custom parameter, with which the login hint can be passed to the IdP.
90+
*/
91+
@property(nonatomic, copy, nullable) NSString *loginHintKey;
92+
8893
/** @property provider
8994
@brief The OAuth provider that does the actual sign in.
9095
*/
@@ -101,7 +106,8 @@ - (instancetype)initWithAuthUI:(FUIAuth *)authUI
101106
buttonColor:(UIColor *)buttonColor
102107
iconImage:(UIImage *)iconImage
103108
scopes:(nullable NSArray<NSString *> *)scopes
104-
customParameters:(nullable NSDictionary<NSString *, NSString*> *)customParameters {
109+
customParameters:(nullable NSDictionary<NSString *, NSString*> *)customParameters
110+
loginHintKey:(nullable NSString *)loginHintKey {
105111
if (self = [super init]) {
106112
_authUI = authUI;
107113
_providerID = providerID;
@@ -112,29 +118,11 @@ - (instancetype)initWithAuthUI:(FUIAuth *)authUI
112118
_scopes = scopes;
113119
_customParameters = customParameters;
114120
_provider = [FIROAuthProvider providerWithProviderID:self.providerID];
115-
_provider.customParameters = self.customParameters;
116-
_provider.scopes = self.scopes;
121+
_loginHintKey = loginHintKey;
117122
}
118123
return self;
119124
}
120125

121-
- (instancetype)initWithProviderID:(NSString *)providerID
122-
buttonLabelText:(NSString *)buttonLabelText
123-
shortName:(NSString *)shortName
124-
buttonColor:(UIColor *)buttonColor
125-
iconImage:(UIImage *)iconImage
126-
scopes:(nullable NSArray<NSString *> *)scopes
127-
customParameters:(nullable NSDictionary<NSString *, NSString*> *)customParameters {
128-
return [self initWithAuthUI:[FUIAuth defaultAuthUI]
129-
providerID:providerID
130-
buttonLabelText:buttonLabelText
131-
shortName:shortName
132-
buttonColor:buttonColor
133-
iconImage:iconImage
134-
scopes:scopes
135-
customParameters:customParameters];
136-
}
137-
138126
#pragma mark - FUIAuthProvider
139127

140128
/** @fn accessToken:
@@ -171,6 +159,17 @@ - (void)signInWithDefaultValue:(nullable NSString *)defaultValue
171159
completion:(nullable FUIAuthProviderSignInCompletionBlock)completion {
172160
self.presentingViewController = presentingViewController;
173161

162+
FIROAuthProvider *provider = self.provider;
163+
provider.scopes = self.scopes;
164+
NSMutableDictionary *customParameters = [NSMutableDictionary dictionary];
165+
if (self.customParameters.count) {
166+
[customParameters addEntriesFromDictionary:self.customParameters];
167+
}
168+
if (self.loginHintKey.length && defaultValue.length) {
169+
customParameters[self.loginHintKey] = defaultValue;
170+
}
171+
provider.customParameters = [customParameters copy];
172+
174173
[self.provider getCredentialWithUIDelegate:nil
175174
completion:^(FIRAuthCredential *_Nullable credential,
176175
NSError *_Nullable error) {

samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUIAuthViewController.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ + (NSArray *)getListOfIDPs:(NSArray<NSIndexPath *> *)selectedRows
429429
buttonColor:buttonColor
430430
iconImage:[UIImage imageWithContentsOfFile:iconPath]
431431
scopes:@[@"user.readwrite"]
432-
customParameters:@{@"prompt" : @"consent"}];
432+
customParameters:@{@"prompt" : @"consent"}
433+
loginHintKey:@"login_hint"];
433434
}
434435
break;
435436
default:

0 commit comments

Comments
 (0)