xHo*_*dek 2 javascript authentication web webauthn
我正在尝试在我们的登录页面上设置 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
});
});
}
Run Code Online (Sandbox Code Playgroud)
一些可能有用的附加信息:
首先,您可以在 Chrome 上使用虚拟身份验证器进行测试,如下图所示。
在 Windows 上,您可以将 Windows Hello 设置为身份验证器并稍后进行测试。
现在针对您的问题提供一些注释
我已经成功让它工作了...你可以尝试看看我的示例代码并使用它们,只有 2 个文件
我仍在清理它以使其成为生产代码(例如,在前端和后端之间传递信息时使用 JWT / Sessions)。
| 归档时间: |
|
| 查看次数: |
6164 次 |
| 最近记录: |