loading
Note:
The other halves of the same container Public-key credentials (passkeys) are WebAuthn, federated sign-in without third-party cookies is FedCM, SMS one-time codes are WebOtp, and wallet credentials are DigitalCredentials. They all go through navigator.credentials; this page is the password store.
Warning:
Chromium only, and secure context onlyPasswordCredential and FederatedCredential are implemented by Chromium. Firefox and Safari expose navigator.credentials for passkeys but not for these, so IsPasswordSupported - not IsSupported - is the check worth branching on.

Support checks

IsSupported / IsPasswordSupported / IsFederatedSupported

Whether the container exists at all, and whether the two credential types this service stores are implemented. During prerender/SSR these return false rather than throwing, so defer them to OnAfterRenderAsync.

C#
@inject Bit.Butil.Credentials credentials

var container = await credentials.IsSupported();
var passwords = await credentials.IsPasswordSupported();
var federated = await credentials.IsFederatedSupported();
Live sample
support check output
Results will appear here when you interact with the samples.

Store a password

StorePassword

Offers a username/password pair to the password manager, which decides for itself whether to prompt. Call it after the server has confirmed the sign-in - storing a credential the server rejected teaches the password manager a wrong answer.

C#
var stored = await credentials.StorePassword(
    id: "[email protected]",
    password: thePassword,
    name: "Ada Lovelace",
    iconUrl: "https://example.com/avatar.png");
Live sample
Account
store password output
Results will appear here when you interact with the samples.

Store a federated sign-in

StoreFederated

Records that this account signs in through an identity provider, so the account chooser can offer "continue with ..." next time. No secret is stored - just the account and the provider's origin.

C#
var stored = await credentials.StoreFederated(
    id: "[email protected]",
    provider: "https://accounts.google.com",
    name: "Ada Lovelace");
Live sample
Provider origin
store federated output
Results will appear here when you interact with the samples.

Get a credential

Get

Asks the browser for a stored credential. With Silent mediation nothing is shown at all - either a credential comes back and you can sign the user in, or nothing does and the visit continues undisturbed. Required always shows the chooser, which is what to use right after a sign-out.

C#
var credential = await credentials.Get(new CredentialRequestOptions
{
    Password = true,
    FederatedProviders = ["https://accounts.google.com"],
    Mediation = CredentialMediation.Silent
});

if (credential is { Type: "password" })
{
    // POST credential.Id / credential.Password to the sign-in endpoint.
}
Live sample
Mediation
get credential output
Results will appear here when you interact with the samples.

Sign out properly

PreventSilentAccess

Turns off silent access until the user next signs in deliberately. Without it, the next visit signs them straight back in - which is the bug behind "I clicked sign out and it logged me back in".

C#
await credentials.PreventSilentAccess();
Live sample
prevent silent access 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 navigator.credentials. Returns default (false) during prerender/SSR instead of throwing.
IsPasswordSupported
ValueTask<bool> IsPasswordSupported()
True when the runtime exposes window.PasswordCredential. This is the check to branch on.
IsFederatedSupported
ValueTask<bool> IsFederatedSupported()
True when the runtime exposes window.FederatedCredential.
StorePassword
ValueTask<bool> StorePassword(string id, string password, string? name = null, string? iconUrl = null)
Offers a username/password pair to the password manager. False when the browser declined or the API is missing.
StoreFederated
ValueTask<bool> StoreFederated(string id, string provider, string? name = null, string? iconUrl = null, string? protocol = null)
Records an account as signing in through an identity provider. No secret is stored.
Get
ValueTask<CredentialInfo?> Get(CredentialRequestOptions? options = null)
Returns a stored credential, or null when there is none or the user dismissed the chooser.
PreventSilentAccess
ValueTask PreventSilentAccess()
Turns off silent access until the next deliberate sign-in. Call it on sign-out.
CredentialRequestOptions
bool Password, string[]? FederatedProviders, string[]? FederatedProtocols, CredentialMediation Mediation (asking for neither throws ArgumentException)
Which credentials are acceptable, and how much UI the browser may show.
CredentialMediation
enum { Optional, Silent, Required, Conditional }
Silent shows no UI; Required always asks; Conditional offers the credential through autofill.
CredentialInfo
string Type, string Id, string? Name, string? IconUrl, string? Password, string? Provider, string? Protocol
The credential the manager handed back. Type is "password" or "federated"; Password is set only on the former.
An unhandled error has occurred. Reload 🗙