IdentityProvider

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

IdentityProvider 接口是 联合凭据管理 (FedCM) API 的一部分,它代表一个 身份提供商 (IdP),并提供对相关信息和功能的访问。

静态方法

close() 实验性

向浏览器发出信号,表示 IdP 登录流程已完成。这对于例如在登录完全完成后且 IdP 已完成从用户收集数据时关闭 IdP 登录对话框是必需的。

getUserInfo() 实验性

在用户返回 IdP 时,返回有关先前已登录用户的信息,可用于提供个性化的欢迎消息和登录按钮。

示例

IdentityProvider.getUserInfo() 的基本用法

以下示例展示了如何使用 getUserInfo() 方法返回特定 IdP 中先前已登录用户的信息。

js
// Iframe displaying a page from the https://idp.example origin
const userInfo = await IdentityProvider.getUserInfo({
  configURL: "https://idp.example/fedcm.json",
  clientId: "client1234",
});

// IdentityProvider.getUserInfo() returns an array of user information.
if (userInfo.length > 0) {
  // Returning accounts should be first, so the first account received
  // is guaranteed to be a returning account
  const name = userInfo[0].name;
  const givenName = userInfo[0].given_name;
  const displayName = givenName || name;
  const picture = userInfo[0].picture;
  const email = userInfo[0].email;

  // …

  // Render a personalized sign-in button using the information returned above
}

规范

规范
Federated Credential Management API
# browser-api-identity-provider-interface

浏览器兼容性

另见