首页 > 解决方案 > 如何检查 WebAuthn 平台类型的身份验证器?

问题描述

所以试图整合WebAuthN。如果与平台无关(FIDO2 安全密钥)检查更容易(一般是否支持 webauthN - 我们继续,也许用户稍后插入 USB 密钥),我找不到检查平台相关的方法(Windows Hello,指纹扫描仪等)身份验证器。isUserVerifyingPlatformAuthenticatorAvailable()看起来就像我所需要的,但

window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()
  .then(() => true)
  .catch(() => false)
  .then((x) => console.log(x))

我的 MacBook(Chrome、Firefox、Safari)总是返回 true。此外 MacBook 没有任何身份验证器并试图继续使用参数

"authenticatorSelection": {
    "authenticatorAttachment" : "platform", 
    "requireResidentKey":false, 
    "userVerification":"preferred"
}

以“此设备不支持此网站请求的安全密钥类型”结尾。消息(我的 MacBook 肯定没有指纹扫描仪,所以这是合理的!)

看到了类似的问题,但只有使用这个的建议isUserVerifyingPlatformAuthenticatorAvailable()

标签: webauthn

解决方案


isUserVerifyingPlatformAuthenticatorAvailable()返回一个 Promise of boolean 所以你的代码应该看起来更像:

window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()
  .then(isAvailable => isAvailable)
  .catch(err => false)
  .then(result => console.log("Platform authenticator is available: " + result));

MDN 文章在这里:https ://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredential/isUserVerifyingPlatformAuthenticatorAvailable


推荐阅读