IdentityCredential: isAutoSelected 屬性
IdentityCredential 介面的只讀屬性 isAutoSelected 指示是否使用 自動重新認證(即,無需使用者干預)執行了聯合登入流程。
當使用 mediation 選項值為 "optional" 或 "silent" 呼叫 navigator.credentials.get() 時,可能會發生自動重新認證。對於 信賴方 (RP) 來說,瞭解自動重新認證是否發生對於分析/效能評估和使用者體驗目的很有用——自動登入可能需要與非自動登入不同的 UI 流程。
值
一個布林值。true 表示使用了自動重新認證;false 表示未使用。
示例
基本的聯合登入和 isAutoSelected 訪問
RP 可以使用 identity 選項呼叫 navigator.credentials.get(),以透過 IdP 請求使用者登入 RP,使用身份聯合。自動重新認證行為由 get() 呼叫中的 mediation 選項控制。
js
async function signIn() {
const identityCredential = await navigator.credentials.get({
identity: {
providers: [
{
configURL: "https://accounts.idp.example/config.json",
clientId: "********",
},
],
},
mediation: "optional", // this is the default
});
// isAutoSelected is true if auto-reauthentication occurred.
const isAutoSelected = identityCredential.isAutoSelected;
}
一個成功的 identity 選項的 navigator.credentials.get() 呼叫會 fulfilled 一個 IdentityCredential 例項,該例項可用於訪問 isAutoSelected 屬性:如果發生了自動重新認證,其值將等於 true。
有關此功能的更多詳細資訊,請檢視 聯合憑證管理 API (FedCM)。此呼叫將啟動 FedCM 登入流程 中所述的登入流程。
規範
| 規範 |
|---|
| Federated Credential Management API # dom-identitycredential-isautoselected |
瀏覽器相容性
載入中…