我正在尝试在我们的登录页面上设置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
就会提示他们
发布于 2021-08-17 23:54:49
首先,您可以在Chrome上使用虚拟身份验证器进行测试,请参见下面的图像。

在windows上,您可以将Windows设置为身份验证器,并在稍后进行测试。
现在为您的问题做一些说明
我设法让它运转起来..。您可以尝试查看我的示例代码并使用它们,只有2个文件。
https://github.com/ais-one/cookbook/blob/develop/js-node/expressjs/public/demo-express/fido.html
我仍然在清理它以使它成为生产代码(例如,在前端和后端之间传递信息时使用JWT/Session)。
如果你还有问题,我们可以在这里讨论.https://github.com/ais-one/cookbook/discussions
发布于 2022-06-14 08:55:22
在我的例子中,我支持的公钥算法列表太窄,无法支持platform身份验证器附件。现在我使用这个algs列表,它可以正常工作。
{"pubKeyCredParams": [
{
"type": "public-key",
"alg": -7
},
{
"type": "public-key",
"alg": -8
},
{
"type": "public-key",
"alg": -36
},
{
"type": "public-key",
"alg": -37
},
{
"type": "public-key",
"alg": -38
},
{
"type": "public-key",
"alg": -39
},
{
"type": "public-key",
"alg": -257
},
{
"type": "public-key",
"alg": -258
},
{
"type": "public-key",
"alg": -259
}]}https://stackoverflow.com/questions/68775598
复制相似问题