我有一个疑问。我已经为Yubico U2F钥匙设置了完整的解决方案。但是现在,我无法停止为具有相同应用程序ID的用户重复注册同一设备。在检查数据库中的键控时,它们为每个重复的注册显示不同的值。请帮帮我。
答案 0 :(得分:1)
如果您使用的是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"
]
}
]
}
}
当浏览器检测到用户试图注册已注册的密钥时,它将告诉用户尝试另一个密钥,并且该请求将完全不会发送到服务器。