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

瀏覽器相容性

另見