【发布时间】:2021-08-13 16:24:49
【问题描述】:
我正在尝试在我们的登录页面上设置 WebAuthn。我到了需要使用navigator.credentials.create() 制作公钥的地方。在 Chrome 上,我不断收到以下错误:Uncaught (in promise) DOMException: The operation either timed out or was not allowed. See: https://www.w3.org/TR/webauthn-2/#sctn-privacy-considerations-client.
以下是相关代码:
if (isAvailable) {
// Get challenge from server
fetch("WebAuthn/WebAuthn.ashx", {
method: "POST"
})
.then(res => res.json())
.then(res => {
const publicKeyCredentialCreationOptions = {
challenge: Uint8Array.from(
res.data, c => c.charCodeAt(0)),
rp: {
id: "localhost",
name: "Company Name"
},
authenticatorSelection: {
authenticatorAttachment: "platform",
userVerification: "discouraged"
},
pubKeyCredParams: [{alg: -7, type: "public-key"}],
user: {
id: Uint8Array.from(
"UZSL85T9AFC", c => c.charCodeAt(0)),
displayName: "User",
name: document.getElementById("tbUser").value // taken from aspx form
}
};
const credential = navigator.credentials.create({
publicKey: publicKeyCredentialCreationOptions
});
});
}
一些可能有用的附加信息:
- 服务器尚未处理此信息,但我认为这并不重要,因为需要在发送凭据之前创建凭据
- 目前在 https://localhost 测试
- 这发生在用户登录之前的登录页面上。这个想法是在用户点击提交后提示用户
【问题讨论】:
-
我遇到了同样的问题。 RP ID 是正确的,我在 https(自签名证书)上,一切都检查出来了。只是不确定发生了什么。边缘浏览器也有同样的问题。
-
如果我在 Chrome Web 工具中启用并添加验证器,它会得到响应。
-
用手机chrome浏览器也可以...
-
@AaronGong 你在哪里添加了什么验证器?不确定我是否需要添加证书才能使其正常工作或什么。如果您能谈谈您是如何得到回复的,那将非常有帮助,谢谢!
-
您好,它是 Chrome DEV 工具中的虚拟身份验证器环境。我会把它添加到答案中
标签: javascript authentication web webauthn