PublicKeyCredential: isUserVerifyingPlatformAuthenticatorAvailable() 靜態方法
PublicKeyCredential 介面的 isUserVerifyingPlatformAuthenticatorAvailable() 靜態方法會返回一個 Promise,如果存在一個使用者驗證型平臺驗證器,該 Promise 將解析為 true。
使用者驗證型平臺驗證器是一種 多因素身份驗證器,它是客戶端裝置的一部分(通常不可移除),並且需要使用者進行操作以識別他們。常見的使用者驗證型平臺驗證器包括:
- Touch ID 或 Face ID(macOS 和 iOS)
- Windows Hello(Windows)
- Android 上的裝置解鎖(指紋、面部、PIN 等)
注意:此方法只能在頂層上下文中使用,例如在 <iframe> 中將不可用。
語法
js
PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()
引數
無。
返回值
一個 Promise,它解析為一個布林值,指示是否存在使用者驗證型平臺驗證器。
注意:在規範的早期版本中,布林值還傳達了使用者同意披露此類驗證器的存在。
異常
返回的 Promise 可能會因以下值而被拒絕
SecurityErrorDOMException-
RP 域無效。
示例
js
PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()
.then((available) => {
if (available) {
// We can proceed with the creation of a PublicKeyCredential
// with this authenticator
} else {
// Use another kind of authenticator or a classical login/password
// workflow
}
})
.catch((err) => {
// Something went wrong
console.error(err);
});
規範
| 規範 |
|---|
| Web Authentication:訪問公鑰憑證的 API - 第 3 級 # dom-publickeycredential-isuserverifyingplatformauthenticatoravailable |
瀏覽器相容性
載入中…