loading
Warning:
Both sides have to be set up FedCM is not something a page can adopt alone. The identity provider hosts /.well-known/web-identity and the config file named by ConfigUrl, with accounts, client-metadata and assertion endpoints behind it, and it calls SetLoginStatus as its own session changes - the browser will not even look for accounts at a provider it believes is logged out. Against a provider that has done none of that, Get returns null.
Note:
Verify the token on the serverFedCmCredential.Token is a bearer credential, usually a signed JWT. Post it to your backend and validate the signature, the issuer, the audience and the nonce you generated there. Reading it in the browser proves nothing.

Support checks

IsSupported / IsLoginStatusSupported

Whether the runtime exposes window.IdentityCredential, and whether navigator.login is there for a provider to report its session with. During prerender/SSR these return false rather than throwing, so defer them to OnAfterRenderAsync.

C#
@inject Bit.Butil.FedCm fedCm

var supported = await fedCm.IsSupported();
var canReportLogin = await fedCm.IsLoginStatusSupported();
Live sample
support check output
Results will appear here when you interact with the samples.

Sign in

Get

Opens the browser's own account dialog for the given provider and resolves with the provider's token, or null when the user dismissed it or no account was found. The nonce belongs to your server: generate it there, and check it comes back in the token.

@inject Bit.Butil.FedCm fedCm
@inject HttpClient http

<button @onclick="SignIn">Sign in</button>

@code {
    private async Task SignIn()
    {
        // The nonce belongs to the server: it is what proves the token came back from a sign-in
        // this backend started, rather than being replayed from another one.
        var nonce = await http.GetStringAsync("/api/auth/nonce");

        var credential = await fedCm.Get(new FedCmOptions
        {
            Providers =
            [
                new FedCmProvider
                {
                    ConfigUrl = "https://idp.example/fedcm.json",
                    ClientId = "your-client-id",
                    Nonce = nonce,
                    Fields = ["name", "email", "picture"]
                }
            ],
            Context = "signin",
            Mediation = CredentialMediation.Optional
        });

        // null when the user dismissed the dialog, or no account was found.
        if (credential is null) return;

        // Reading the token in the browser proves nothing - the backend validates the signature,
        // the issuer, the audience and the nonce it generated.
        await http.PostAsJsonAsync("/api/auth/fedcm", new { credential.Token });
    }
}
Live sample
Provider config URL
Client id
Context
Mediation
fedcm sign-in output
Results will appear here when you interact with the samples.

Disconnect an account

Disconnect

Severs the link between this relying party and one account at the provider, so the next sign-in needs fresh consent. The provider's disconnect endpoint does the work; the browser only forwards the request.

C#
var disconnected = await fedCm.Disconnect(
    configUrl: "https://idp.example/fedcm.json",
    clientId: "your-client-id",
    accountHint: "[email protected]");
Live sample
Account hint
disconnect output
Results will appear here when you interact with the samples.

Report the provider's own session

SetLoginStatus

Only an identity provider's own pages call this, and they call it on every session change. Set LoggedIn after a sign-in and LoggedOut after a sign-out: the browser skips the accounts endpoint entirely for a provider it believes is logged out.

C#
// On the identity provider's own origin:
await fedCm.SetLoginStatus(FedCmLoginStatus.LoggedIn);

// ...and on sign-out:
await fedCm.SetLoginStatus(FedCmLoginStatus.LoggedOut);
Live sample
login status output
Results will appear here when you interact with the samples.

API reference

Member
Signature
Description
IsSupported
ValueTask<bool> IsSupported()
True when the runtime exposes window.IdentityCredential. Returns default (false) during prerender/SSR instead of throwing.
Get
ValueTask<FedCmCredential?> Get(FedCmOptions options)
Runs the browser-mediated sign-in. Null when the user dismissed the dialog, no account matched, or the browser refused.
Disconnect
ValueTask<bool> Disconnect(string configUrl, string clientId, string accountHint)
Asks the provider to disconnect one account from this relying party.
IsLoginStatusSupported
ValueTask<bool> IsLoginStatusSupported()
True when the runtime exposes navigator.login.
SetLoginStatus
ValueTask<bool> SetLoginStatus(FedCmLoginStatus status)
An identity provider telling the browser whether anyone is signed in on its own origin.
FedCmOptions
FedCmProvider[] Providers, string? Context, CredentialMediation Mediation
The providers on offer and how the browser should present the choice. Chromium honours the first provider only.
FedCmProvider
string ConfigUrl, string ClientId, string? Nonce, string? LoginHint, string? DomainHint, string[]? Fields, object? Parameters
One identity provider. Parameters is passed through as the provider dictionary's params.
FedCmCredential
string? Id, string Token, bool IsAutoSelected, string? ConfigUrl
The provider's token. IsAutoSelected is true when the browser signed the user in without asking. ConfigUrl is null where the browser does not report which provider answered.
FedCmLoginStatus
enum { LoggedIn, LoggedOut }
What SetLoginStatus tells the browser about the provider's own session.
An unhandled error has occurred. Reload 🗙