靜態方法
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 |
瀏覽器相容性
載入中…
另見
- Federated Credential Management API on privacysandbox.google.com (2023)