FederatedCredential: FederatedCredential() constructor

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The FederatedCredential() constructor creates a new FederatedCredential object. In supporting browsers, an instance of this class may be passed the credential received from the init object for global fetch().

Syntax

js
new FederatedCredential(data)

Parameters

data

A FederatedCredentialInit object. An object with the following properties:

name Optional

A string representing the credential username.

iconURL Optional

A string representing the URL of an icon or avatar to be associated with the credential.

origin

A string representing the credential's origin. FederatedCredential objects are origin-bound, so they will only be usable on the origin specified here.

provider

A string which identifies the credentials' federated identity provider, specified as the origin that the provider uses to sign users in (for example "https://www.facebook.com" or "https://accounts.google.com").

protocol Optional

A string representing the protocol of the credentials' federated identity provider (for example, "openidconnect").

Examples

Creating a federated identity credential

js
const credData = {
  id: "1234",
  name: "Serpentina",
  origin: "https://example.org",
  protocol: "openidconnect",
  provider: "https://provider.example.org",
};

const fedCred = new FederatedCredential(credData);

// Store it
navigator.credentials.store(fedCred).then(() => {
  // Do something else
});

Specifications

Specification
Credential Management Level 1
# dom-federatedcredential-federatedcredential

Browser compatibility