firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

AuthProvider class lacks API to retrieve provider name

Open ensonic opened this issue 1 year ago • 7 comments

Operating System

Any

Environment (if applicable)

Google Chrome 130.0.6723.58 (Official Build) (64-bit)

Firebase SDK Version

10.12.0

Firebase SDK Product(s)

Auth

Project Tooling

Angular

Detailed Problem Description

I configure a custom OIDC provider following https://firebase.google.com/docs/auth/web/openid-connect#before_you_begin

In my app we have a dialog for the user to choose the login provider to use. Since there are multiple OIDC providers I'd like to use human readble labels. When I create the provider with the provider-id, I would expect an api like provider.GetName() to retrieve that name that I specified when I created the provider.

The api docs don't list such an api: https://firebase.google.com/docs/reference/node/firebase.auth.AuthProvider

Steps and code to reproduce issue

See above.

ensonic avatar Oct 22 '24 10:10 ensonic

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Oct 22 '24 10:10 google-oss-bot

I've dumped the provider object and it does not seem to contain the information, so it is more that just adding api for it.

ensonic avatar Oct 23 '24 07:10 ensonic

Let me know if I am misunderstanding but I'm creating an OAuthProvider as the instructions in the guide doc you linked say to do and this seems to work?

import { OAuthProvider } from 'firebase/auth';

const provider = new OAuthProvider('custom name');
console.log(provider.providerId); // "custom name"

hsubox76 avatar Oct 23 '24 16:10 hsubox76

providerId is e.g. oidc.my-provider´, but when creating the provider in firebase console I named it e.g. "My Provider". I'd like to access the display name to pt it on a button label. I can probably implement some reverse transform, but I won't be able to recover the original name in all cases (e.g My Super-Providerbecomesoidc.my-super-provider` and I won't know which minus was a space and which a minus).

ensonic avatar Oct 23 '24 17:10 ensonic

Hi @hsubox76, may I expose the console “Display name” as a read-only provider.displayName property? Plan: fetch the config once per auth instance, cache it, and surface the field. No new backend call, just plumbing.

singhaditya73 avatar Dec 08 '25 16:12 singhaditya73

Hi @singhaditya73,

Hi @hsubox76, may I expose the console “Display name” as a read-only provider.displayName property? Plan: fetch the config once per auth instance, cache it, and surface the field. No new backend call, just plumbing.

I'm from the core JS SDK engineering team working with @hsubox76.

We will need the approval of the Firebase Auth team for API and behavioral changes like this.

To help expedite their review, could you please provide a clear description of the desired user experience, the thoughts on how the change would be implemented, and what the API change would be?

Final acceptance of a Pull Request will be at their discretion and contingent on their design and API approval. Thanks!

DellaBitta avatar Dec 09 '25 17:12 DellaBitta

Hello @DellaBitta here are the three bullets you asked for

User Experience

Developers set a display name in the Firebase Console (e.g., "My Company SSO") but currently must hard-code it again in their app or parse the provider ID (which loses casing/spaces). Instead:

const provider = new OAuthProvider('oidc.my-provider');
loginButton.textContent = provider.displayName; // "My Company SSO" from console

API Change

Add one read-only property (non-breaking):

class OAuthProvider {
  readonly displayName: string | null;  // null if unavailable
}
class SAMLAuthProvider {
  readonly displayName: string | null;
}

Implementation

  • Source: getProjectConfig RPC already returns provider configs; extend internal ProviderConfig type with the displayName field
  • Caching: Reuse existing per-Auth-instance config cache (one fetch per app lifetime, no new network calls)
  • Fallback: Returns null if config unavailable or provider not found
  • Scope: ~30 lines each in oauth.ts/saml.ts + types + tests

Does this align with what the Auth team needs for review?

singhaditya73 avatar Dec 09 '25 18:12 singhaditya73

Thank you. I'll send it off to the Auth team for review. I think one difficulty is that the OAuthProvider constructor is synchronous and so the Provider names would need to be queried before OAuthProvider can be used. Currently getProjectConfig is only invoked in specific Auth flows, and not when the Auth instance is initialized.

But I'll send it to the team! Thanks again!

DellaBitta avatar Dec 10 '25 18:12 DellaBitta