大网数据广告活动
Web 标准与前端开发

Federated Credential Management (FedCM) API

· 52CE 我爱测

The **Federated Credential Management API** (or _FedCM API_) provides a standard mechanism for Identity provider (IdPs) to make identity federation services available on the web in a privacy-preserving way, without the need for third-party cookies and redirects. This includes a J

FedCM API

The Federated Credential Management API (or FedCM API) provides a standard mechanism for Identity provider (IdPs) to make identity federation services available on the web in a privacy-preserving way, without the need for third-party cookies and redirects. This includes a JavaScript API that enables the use of federated authentication for activities such as signing in or signing up on a website.

FedCM concepts

Identity federation is the delegation of user authentication from a website requiring user sign-up or sign-in, such as an e-commerce or social networking site (also known as a Relying party or RP), to a trusted third-party identity provider (IdP) such as Google, Facebook/Meta, GitHub, etc.

RPs can integrate with IdPs, allowing users to sign-in using the accounts they have registered with the IdP. Identity federation via a small set of dedicated IdPs has improved web authentication in terms of security, consumer confidence, and user experience, as compared to each site managing its own sign-in needs with separate usernames and passwords.

The problem is that traditional identity federation relies on iframes, redirects, and third-party cookies, which are also used for third-party tracking. Browsers are limiting the usage of these features in an effort to preserve user privacy, but a side effect is that this makes valid, non-tracking uses more difficult to implement, which includes identity federation.

This affects federated sign-in in general, as well as more specific identity federation use cases:

  • OIDC front-channel logout: This flow requires the IDP to embed several RP <iframe>s, which rely on RP cookies.
  • Social Widgets: In order to provide social widgets, the IdP third-party cookie must be provided from the RP top-level origin.
  • Personalized buttons: The display of personalized sign in information on a button in the RP origin is implemented as an IdP <iframe> that requires third-party cookies.
  • Session Refresh without top-level navigation or popups.

FedCM aims to work around this problem, providing a dedicated mechanism for federated identity flows on the web, and enabling supporting browsers to provide special UI elements on RPs, allowing users to choose an IdP account to use for sign-in.

There are two parts to using the FedCM API, which are covered in the linked guides below:

  1. IdP integration with FedCM — what an identity provider needs to provide so that an RP can integrate with it.
  2. RP federated sign-in — the FedCM functionality an RP needs to use to sign a user in using their IdP account. A FedCM sign-in request is initiated using the CredentialsContainer.get method.

[!NOTE] Google Sign In is an example of an IdP that already supports FedCM. Migrate to FedCM provides instructions for RPs wishing to migrate existing apps using Google Sign In to federated sign-in.

Permissions Policy integration and <iframe> support

The Permissions-Policy/identity-credentials-get Permissions-Policy can be used to control permission to use FedCM. More specifically, it permits usage of the following methods:

  • CredentialsContainer.get()
  • IdentityCredential.disconnect_static
  • IdentityProvider.getUserInfo_static

Developers can explicitly grant permission for an iframe to use FedCM via the allow attribute:

<iframe src="3rd-party.example" allow="identity-credentials-get"></iframe>

The availability of FedCM within <iframe>s enables a couple of use cases:

  • Larger sites won't want a third-party sign-in script to gain control over the top-level frame; instead they will want to add that script and invoke FedCM from within an iframe.
  • Some <iframes> may themselves require federated authentication.

Interfaces

  • IdentityCredential
    • : Represents a user identity credential arising from successful federated authentication. A successful CredentialsContainer.get call that includes an identity option fulfills with an IdentityCredential instance.
  • IdentityCredentialError
    • : Represents an authentication error indicating that the user agent did not receive an identity assertion after the user has asked to authenticate using a federated credential.
  • IdentityProvider
    • : Represents an IdP and provides access to related information and functionality.
  • NavigatorLogin

Extensions to other interfaces

  • CredentialsContainer.get(), the identity option.
    • : identity is an object containing details of federated IdPs that a relying party (RP) website can use to sign users in. It causes a get() call to initiate a request for a user to sign in to an RP with an IdP.
  • Navigator.login
    • : Provides access to the browser's NavigatorLogin object.

HTTP headers

Examples

For example code, see:

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。