我有个疑问。我已经围绕 Yubico U2F 键设置了一个完整的解决方案。但是现在,我无法停止为同一应用程序 ID 的用户重复注册同一设备。在检查我的数据库上的键柄时,它们为每个重复注册显示不同的值。请帮帮我。
问问题
406 次
1 回答
3
如果您使用的是 WebAuthn API,则可以在尝试使用“excludeCredentials”密钥添加新密钥时将所有已注册的密钥发送到客户端。这些凭据的格式与尝试登录时的格式相同。
excludeCredentials — 包含已向用户注册的凭据列表。然后将该列表提供给验证器,如果验证器识别其中任何一个,它会取消操作并返回错误 CREDENTIAL_EXISTS,从而防止同一验证器的重复注册。
来源:https ://medium.com/@herrjemand/introduction-to-webauthn-api-5fd1fb46c285
客户端在添加新密钥时收到的 JSON 示例可能是:
{
"publicKey":{
"rp":{
"name":"YourApp",
"id":"YourAddress"
},
"authenticatorSelection":{
"userVerification":"preferred"
},
"user":{
"id":"UserId",
"name":"Username",
"displayName":"displayName"
},
"pubKeyCredParams":[
{
"type":"public-key",
"alg":-7
}
],
"attestation":"direct",
"extensions":{
"exts":true
},
"timeout":20000,
"challenge":"...",
"excludeCredentials":[
{
"id":"...",
"type":"public-key",
"transports":[
"usb",
"ble",
"nfc",
"internal"
]
},
{
"id":"...",
"type":"public-key",
"transports":[
"usb",
"ble",
"nfc",
"internal"
]
}
]
}
}
当浏览器检测到用户尝试注册一个已经注册的密钥时,它会告诉用户尝试另一个密钥,并且根本不会向服务器发送请求。
于 2019-04-25T13:45:24.063 回答