# Federated Credential Management (FedCM)

> How a relying party requests an IdentityCredential through FedCM, detects support, handles policy and request failures, and keeps a fallback sign-in path.

The Federated Credential Management API lets a relying party ask the browser to mediate sign-in with an identity provider. The relying party calls `navigator.credentials.get()` with an `identity` request, and a successful request returns an `IdentityCredential` carrying the provider's token ([FedCM API](https://www.w3.org/TR/fedcm/), W3C).

## Where it is supported

BCD records `IdentityCredential` from Chrome 108 and mirrors support to Chrome for Android and Edge. Opera and Samsung Internet are also recorded, along with Meta Quest Browser. It records no support in Firefox or Safari; Android WebView is likewise unsupported, so FedCM is not Baseline (BCD `api.IdentityCredential`; [FedCM API](https://developer.mozilla.org/en-US/docs/Web/API/FedCM_API), MDN).

## Syntax

```js
const credential = await navigator.credentials.get({
  identity: {
    providers: [{
      configURL: 'https://idp.example/fedcm.json',
      clientId: 'rp-client-id',
    }],
  },
});
```

The browser fetches the provider configuration and related identity-provider endpoints, mediates its account UI, and returns the credential to the relying party. FedCM is a secure-context API exposed on `Window` through the Credential Management API ([Browser API](https://www.w3.org/TR/fedcm/#browser-api), W3C).

| Expression | Value |
|---|---|
| `navigator.credentials.get(options)` | A promise that returns an `IdentityCredential` after the mediated request succeeds |
| `options.identity.providers` | The identity-provider configurations available to the request |
| `credential.token` | The token minted by the selected identity provider |
| `credential.isAutoSelected` | Whether the browser automatically selected the credential during the UI flow |

## Parameters

`identity.providers` is a sequence of provider configurations. The core fields used by the W3C example are `configURL`, which identifies the provider configuration, and `clientId`, which identifies the relying party to that provider. The request can also carry provider-defined values such as `nonce` and `loginHint`, as well as `domainHint`, as documented by the specification.

| Member | Required | Purpose |
|---|---|---|
| `configURL` | Yes | Gives the full URL of the identity provider's configuration file |
| `clientId` | Yes | Gives the relying party identifier issued by the identity provider |
| `nonce` | No | Passes a relying-party value to the identity provider |
| `loginHint` | No | Selects accounts whose account data contains the matching login hint |
| `domainHint` | No | Selects accounts whose account data contains the matching domain hint |

The returned `IdentityCredential` has a `token` supplied by the identity provider. The specification defines `isAutoSelected` to report whether the browser automatically selected the credential during the UI flow ([IdentityCredential interface](https://www.w3.org/TR/fedcm/#browser-api-identity-credential-interface), W3C).

A relying party needs an identity provider with the configuration and endpoints described by FedCM before this call can complete. Chrome's relying-party guide also requires pages with a restrictive Content Security Policy `connect-src` directive to allow the endpoints named by that configuration ([Implement FedCM on the relying-party side](https://developer.chrome.com/docs/identity/fedcm/implement/relying-party), Chrome for Developers).

## Exceptions

- A document blocked by the `identity-credentials-get` Permissions Policy receives a promise rejected with `NotAllowedError`. The feature's default allowlist is `self`; a cross-origin iframe needs an explicit `allow="identity-credentials-get"` grant ([Permissions Policy integration](https://www.w3.org/TR/fedcm/#permissions-policy-integration), W3C).
- The specification maps provider-fetch failures and a missing eligible account to `NetworkError`. A request blocked by `identity-credentials-get` instead rejects with `NotAllowedError`, while an invalid `configURL` rejects with `InvalidStateError` ([Create an IdentityCredential](https://www.w3.org/TR/fedcm/#create-an-identitycredential), W3C).
- FedCM needs identity-provider support, so a relying party cannot deploy it independently. The first example reveals a link to the site's existing sign-in route in unsupported browsers.

The exception name identifies a class of failure, not a complete diagnosis. Keep the fallback route usable after an unsupported-browser branch, an empty result, a policy rejection, or a provider request failure. The examples report the returned `DOMException.name` and leave the ordinary sign-in link available instead of assuming that feature detection predicts a successful provider exchange.

:::caution
Chromium rejects a concurrent FedCM request with `NotAllowedError: Only one navigator.credentials.get request may be outstanding at one time.` The exact string is defined in Chromium's [`authentication_credentials_container.cc`](https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/modules/credentialmanagement/authentication_credentials_container.cc) (chromium.googlesource.com).
:::

## Examples

Replace the sample provider URL, client ID, `/session/fedcm` session endpoint, and fallback URL before running these examples. Serve the page in a secure context, and configure the identity-provider endpoints first. The visible status text in each example is illustrative output produced by its own branches; it is not a browser measurement.

### Requesting a credential with a fallback

Test both the Credential Management container and `IdentityCredential`. If either is absent, or if the mediated request does not return a token, continue through the site's existing sign-in route. Chrome's relying-party guide uses the `IdentityCredential` check and directs unsupported browsers to another identity solution ([Implement FedCM on the relying-party side](https://developer.chrome.com/docs/identity/fedcm/implement/relying-party), Chrome for Developers).

```html
<button id="federated-sign-in" type="button">Sign in with your identity provider</button>
<a id="sign-in-fallback" href="/sign-in" hidden>Use the standard sign-in page</a>
<p id="sign-in-status" role="status"></p>

<script type="module">
const button = document.querySelector('#federated-sign-in');
const fallback = document.querySelector('#sign-in-fallback');
const status = document.querySelector('#sign-in-status');

function useFallback(message) {
  status.textContent = message;
  fallback.hidden = false;
}

async function sendTokenToServer(token) {
  const response = await fetch('/session/fedcm', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ token }),
  });
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
}

async function signIn() {
  if (!('credentials' in navigator) || !('IdentityCredential' in window)) {
    useFallback('FedCM is unavailable. Use the standard sign-in page.');
    return;
  }

  try {
    const credential = await navigator.credentials.get({
      identity: {
        providers: [{
          configURL: 'https://idp.example/fedcm.json',
          clientId: 'rp-client-id',
        }],
      },
    });

    if (!credential?.token) {
      useFallback('No credential was returned. Use the standard sign-in page.');
      return;
    }
    await sendTokenToServer(credential.token);
    status.textContent = 'The credential was sent to the server.';
  } catch (error) {
    useFallback(`FedCM did not complete: ${error.name}`);
  }
}

button.addEventListener('click', signIn);
</script>
```

The example defines every referenced element and helper. Send the opaque token to the relying party's server for validation. Do not treat the presence of `IdentityCredential` as proof that a particular provider is configured or that the request will succeed. When a branch calls `useFallback()`, the status explains the branch and the ordinary `/sign-in` link becomes visible.

### Avoiding a concurrent-request failure

Chromium permits one outstanding FedCM `navigator.credentials.get()` request at a time. Disable the initiating button while the promise is pending, restore it in `finally`, and reveal the ordinary sign-in link when the request rejects. The source-linked caution above gives Chromium's exact concurrent-request exception.

```html
<button id="fedcm-once" type="button">Continue with FedCM</button>
<a id="ordinary-sign-in" href="/sign-in" hidden>Use the standard sign-in page</a>
<p id="fedcm-result" role="status"></p>

<script type="module">
const button = document.querySelector('#fedcm-once');
const fallback = document.querySelector('#ordinary-sign-in');
const result = document.querySelector('#fedcm-result');

button.addEventListener('click', async () => {
  button.disabled = true;
  try {
    const credential = await navigator.credentials.get({
      identity: { providers: [{
        configURL: 'https://idp.example/fedcm.json',
        clientId: 'rp-client-id',
      }] },
    });
    result.textContent = credential?.token
      ? 'FedCM returned a token.'
      : 'FedCM returned no token.';
    fallback.hidden = Boolean(credential?.token);
  } catch (error) {
    result.textContent = `FedCM failed: ${error.name}`;
    fallback.hidden = false;
  } finally {
    button.disabled = false;
  }
});
</script>
```

With the button disabled, this interface does not start a second request from another click while the first promise is pending. If the browser rejects the request for another documented reason, the catch branch prints its exception name and reveals `/sign-in`. A site with more than one FedCM trigger must coordinate those triggers around the same pending operation to apply the same recovery path.

## See also

- [Credential Management API](/reference/capabilities/credential-management/)
- [WebAuthn and passkeys](/reference/capabilities/webauthn-passkeys/)
- [Browser compatibility data](/compatibility/)
- [Federated Credential Management API](https://www.w3.org/TR/fedcm/) (w3.org)
- [Implement an identity solution with FedCM on the relying-party side](https://developer.chrome.com/docs/identity/fedcm/implement/relying-party) (Chrome for Developers)