Skip to content

Commit 3eb86ec

Browse files
Adds ability to customize IdP buttons. (#730)
* Adds ability to customize IdP buttons. Allow customization of native providers. In addition, allow ability to override the entire button label via "fullLabel". This will be used instead of "Sign in with $providerName" for the long name. However, for the short name, $providerName is still used.
1 parent 205f66d commit 3eb86ec

File tree

13 files changed

+264
-47
lines changed

13 files changed

+264
-47
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* Extends the ability to customize the default IdP buttons (provider name, icon URL and background color) for providers like Google and Email.
2+
* Adds the ability to overwrite the entire button label via `fullLabel` for all buttons.

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,16 @@ parameters.
641641
</td>
642642
</tr>
643643
<tr>
644+
<td>fullLabel</td>
645+
<td>No</td>
646+
<td>
647+
The full label of the button. Instead of "Sign in with $providerName", this
648+
button label will be used.
649+
<em>Default:</em>
650+
<code>Sign in with $providerName</code>
651+
</td>
652+
</tr>
653+
<tr>
644654
<td>buttonColor</td>
645655
<td>No</td>
646656
<td>
@@ -694,6 +704,8 @@ ui.start('#firebaseui-auth-container', {
694704
{
695705
provider: 'microsoft.com',
696706
providerName: 'Microsoft',
707+
// To override the full label of the button.
708+
// fullLabel: 'Login with Microsoft',
697709
buttonColor: '#2F2F2F',
698710
iconUrl: '<icon-url-of-sign-in-button>',
699711
loginHintKey: 'login_hint',
@@ -740,6 +752,16 @@ OIDC providers' `signInOptions` support the following configuration parameters.
740752
</td>
741753
</tr>
742754
<tr>
755+
<td>fullLabel</td>
756+
<td>No</td>
757+
<td>
758+
The full label of the button. Instead of "Sign in with $providerName", this
759+
button label will be used.
760+
<em>Default:</em>
761+
<code>Sign in with $providerName</code>
762+
</td>
763+
</tr>
764+
<tr>
743765
<td>buttonColor</td>
744766
<td>Yes</td>
745767
<td>
@@ -770,8 +792,10 @@ OIDC providers' `signInOptions` support the following configuration parameters.
770792
ui.start('#firebaseui-auth-container', {
771793
signInOptions: [
772794
{
773-
provider: 'oidc.myProvider`,
795+
provider: 'oidc.myProvider',
774796
providerName: 'MyOIDCProvider',
797+
// To override the full label of the button.
798+
// fullLabel: 'Employee Login',
775799
buttonColor: '#2F2F2F',
776800
iconUrl: '<icon-url-of-sign-in-button>',
777801
customParameters: {
@@ -814,6 +838,16 @@ SAML providers' `signInOptions` support the following configuration parameters.
814838
</td>
815839
</tr>
816840
<tr>
841+
<td>fullLabel</td>
842+
<td>No</td>
843+
<td>
844+
The full label of the button. Instead of "Sign in with $providerName", this
845+
button label will be used.
846+
<em>Default:</em>
847+
<code>Sign in with $providerName</code>
848+
</td>
849+
</tr>
850+
<tr>
817851
<td>buttonColor</td>
818852
<td>Yes</td>
819853
<td>
@@ -839,6 +873,8 @@ ui.start('#firebaseui-auth-container', {
839873
{
840874
provider: 'saml.myProvider',
841875
providerName: 'MySAMLProvider',
876+
// To override the full label of the button.
877+
// fullLabel: 'Constractor Portal',
842878
buttonColor: '#2F2F2F',
843879
iconUrl: '<icon-url-of-sign-in-button>'
844880
}

externs/firebaseui-externs.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,38 @@ firebaseui.auth.Callbacks.prototype.uiShown = function() {};
682682
*/
683683
firebaseui.auth.SignInOption = function() {};
684684

685+
/**
686+
* The provider name displayed to end users
687+
* (sign-in button label/linking prompt).
688+
* Default: provider ID
689+
*
690+
* @type {string|undefined}
691+
*/
692+
firebaseui.auth.SignInOption.prototype.providerName;
693+
694+
/**
695+
* The full label of the button, instead of "Sign in with $providerName".
696+
* Default: "Sign in with $providerName".
697+
*
698+
* @type {string|undefined}
699+
*/
700+
firebaseui.auth.SignInOption.prototype.fullLabel;
701+
702+
/**
703+
* The color of the sign-in button.
704+
*
705+
* @type {string|undefined}
706+
*/
707+
firebaseui.auth.SignInOption.prototype.buttonColor;
708+
709+
/**
710+
* The URL of the Identity Provider's icon. This will be displayed on the
711+
* provider's sign-in button, etc.
712+
*
713+
* @type {string|undefined}
714+
*/
715+
firebaseui.auth.SignInOption.prototype.iconUrl;
716+
685717
/**
686718
* The provider ID for the provided sign in option,
687719
* eg: `firebase.auth.GoogleAuthProvider.PROVIDER_ID`.

firebaseuihandler/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ const configs = {
137137
{
138138
provider: 'saml.my-provider1',
139139
providerName: 'SAML provider',
140+
// To customize the full label:
141+
// fullLabel: 'ACME Portal',
140142
buttonColor: '#4666FF',
141143
iconUrl: 'https://www.example.com/photos/my_idp/saml.png'
142144
},
@@ -161,6 +163,8 @@ const configs = {
161163
{
162164
provider: 'oidc.my-provider1',
163165
providerName: 'OIDC provider',
166+
// To customize the full label:
167+
// fullLabel: 'Contractor Login',
164168
buttonColor: '#4666FF',
165169
iconUrl: 'https://www.example.com/photos/my_idp/oidc.png'
166170
},

javascript/widgets/config.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,30 @@ class Config {
237237
googArray.contains(
238238
UI_SUPPORTED_PROVIDERS,
239239
option['provider'])) {
240-
// For built-in providers, provider display name, button color and
241-
// icon URL are fixed. The login hint key is also automatically set for
242-
// built-in providers that support it.
243-
return {
240+
// The login hint key is also automatically set for built-in providers
241+
// that support it.
242+
const providerConfig = {
244243
providerId: option['provider'],
244+
// Since developers may be using G-Suite for Google sign in or
245+
// want to label email/password as their own provider, we should
246+
// allow customization of these attributes.
247+
providerName: option['providerName'] || null,
248+
fullLabel: option['fullLabel'] || null,
249+
buttonColor: option['buttonColor'] || null,
250+
iconUrl: option['iconUrl'] ?
251+
util.sanitizeUrl(option['iconUrl']) : null,
245252
};
253+
for (const key in providerConfig) {
254+
if (providerConfig[key] === null) {
255+
delete providerConfig[key];
256+
}
257+
}
258+
return providerConfig;
246259
} else {
247260
return {
248261
providerId: option['provider'],
249262
providerName: option['providerName'] || null,
263+
fullLabel: option['fullLabel'] || null,
250264
buttonColor: option['buttonColor'] || null,
251265
iconUrl: option['iconUrl'] ?
252266
util.sanitizeUrl(option['iconUrl']) : null,
@@ -914,11 +928,15 @@ Config.SignInFlow = {
914928
* The provider config object for generic providers.
915929
* providerId: The provider ID.
916930
* providerName: The display name of the provider.
931+
* fullLabel: The full button label. If both providerName and fullLabel are
932+
* provided, we will use fullLabel for long name and providerName for short
933+
* name.
917934
* buttonColor: The color of the sign in button.
918935
* iconUrl: The URL of the icon on sign in button.
919936
* loginHintKey: The name to use for the optional login hint parameter.
920937
* @typedef {{
921938
* providerId: string,
939+
* fullLabel: (?string|undefined),
922940
* providerName: (?string|undefined),
923941
* buttonColor: (?string|undefined),
924942
* iconUrl: (?string|undefined),

javascript/widgets/config_test.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,16 @@ testSuite({
311311
{
312312
'provider': 'google.com',
313313
'scopes': ['foo', 'bar'],
314-
// providerName, buttonColor and iconUrl should be override with null.
315-
'providerName': 'Google',
314+
'providerName': 'MyIdp',
315+
'fullLabel': 'MyIdp Portal',
316316
'buttonColor': '#FFB6C1',
317317
'iconUrl': '<url-of-the-icon-of-the-sign-in-button>',
318318
},
319319
'facebook.com',
320320
{
321321
'provider': 'microsoft.com',
322322
'providerName': 'Microsoft',
323+
'fullLabel': 'Microsoft Login',
323324
'buttonColor': '#FFB6C1',
324325
'iconUrl': '<url-of-the-icon-of-the-sign-in-button>',
325326
'loginHintKey': 'login_hint',
@@ -333,20 +334,26 @@ testSuite({
333334
assertEquals(4, providerConfigs.length);
334335
assertObjectEquals({
335336
providerId: 'google.com',
337+
providerName: 'MyIdp',
338+
fullLabel: 'MyIdp Portal',
339+
buttonColor: '#FFB6C1',
340+
iconUrl: '<url-of-the-icon-of-the-sign-in-button>',
336341
}, providerConfigs[0]);
337342
assertObjectEquals({
338343
providerId: 'facebook.com',
339344
}, providerConfigs[1]);
340345
assertObjectEquals({
341346
providerId: 'microsoft.com',
342347
providerName: 'Microsoft',
348+
fullLabel: 'Microsoft Login',
343349
buttonColor: '#FFB6C1',
344350
iconUrl: '<url-of-the-icon-of-the-sign-in-button>',
345351
loginHintKey: 'login_hint',
346352
}, providerConfigs[2]);
347353
assertObjectEquals({
348354
providerId: 'yahoo.com',
349355
providerName: null,
356+
fullLabel: null,
350357
buttonColor: null,
351358
iconUrl: null,
352359
loginHintKey: null,
@@ -358,15 +365,17 @@ testSuite({
358365
{
359366
'provider': 'google.com',
360367
'scopes': ['foo', 'bar'],
361-
// providerName, buttonColor and iconUrl should be override with null.
362-
'providerName': 'Google',
368+
'providerName': 'MyIdp',
369+
'fullLabel': 'MyIdp Portal',
363370
'buttonColor': '#FFB6C1',
364371
'iconUrl': '<url-of-the-icon-of-the-sign-in-button>',
372+
'loginHintKey': 'other',
365373
},
366374
'facebook.com',
367375
{
368376
'provider': 'microsoft.com',
369377
'providerName': 'Microsoft',
378+
'fullLabel': 'Microsoft Login',
370379
'buttonColor': '#FFB6C1',
371380
'iconUrl': '<url-of-the-icon-of-the-sign-in-button>',
372381
'loginHintKey': 'login_hint',
@@ -381,13 +390,18 @@ testSuite({
381390
]);
382391
assertObjectEquals({
383392
providerId: 'google.com',
393+
providerName: 'MyIdp',
394+
fullLabel: 'MyIdp Portal',
395+
buttonColor: '#FFB6C1',
396+
iconUrl: '<url-of-the-icon-of-the-sign-in-button>',
384397
}, config.getConfigForProvider('google.com'));
385398
assertObjectEquals({
386399
providerId: 'facebook.com',
387400
}, config.getConfigForProvider('facebook.com'));
388401
assertObjectEquals({
389402
providerId: 'microsoft.com',
390403
providerName: 'Microsoft',
404+
fullLabel: 'Microsoft Login',
391405
buttonColor: '#FFB6C1',
392406
iconUrl: '<url-of-the-icon-of-the-sign-in-button>',
393407
loginHintKey: 'login_hint',
@@ -396,6 +410,7 @@ testSuite({
396410
assertObjectEquals({
397411
providerId: 'yahoo.com',
398412
providerName: 'Yahoo',
413+
fullLabel: null,
399414
buttonColor: '#FFB6C1',
400415
iconUrl: 'about:invalid#zClosurez',
401416
loginHintKey: null,

javascript/widgets/uihandlerconfig_test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ testSuite({
5454
{
5555
hd: 'sub-acme.com',
5656
provider: 'password',
57+
fullLabel: 'Sign in as Employee',
5758
requireDisplayName: false,
5859
},
5960
],
@@ -70,6 +71,7 @@ testSuite({
7071
{
7172
hd: 'ocp-supplier1.com',
7273
provider: 'saml.my-provider1',
74+
fullLabel: 'Contractor Portal',
7375
providerName: 'SAML provider',
7476
buttonColor: '#4413AD',
7577
iconUrl: 'https://www.example.com/photos/my_idp/saml.png',

0 commit comments

Comments
 (0)