javascript - 如何在 iOS 中使用 webauthn 并做出反应?
问题描述
if (navigator.credentials && window.PublicKeyCredential) {
const available = await window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
if (available) {
const newCredentialInfo = await navigator.credentials.create(options);
var response = newCredentialInfo.response;
var clientExtensionsResults = newCredentialInfo.getClientExtensionResults();
alert(JSON.stringify(response))
alert(JSON.stringify(clientExtensionsResults));
}
else {
alert("Unsupported");
}
}
让我只使用私钥(usb 或 smthg。但如果我将它options.publicKey
与 JavaScript 和 html 一起使用,一切正常。它让我可以使用 FaveID 进行身份验证,但响应为空。
我的选择是
{"rp":{"id":"https://im-faceid.netlify.app","name":"netlify.app"},"user":{"id":{"0":97,"1":87,"2":120,"3":53,"4":89,"5":87,"6":49,"7":118,"8":99,"9":109,"10":82,"11":104,"12":99,"13":50,"14":57,"15":50},"name":"test","displayName":"Test User"},"challenge":{"0":79,"1":72,"2":78,"3":122,"4":101,"5":71,"6":86,"7":111},"pubKeyCredParams":[{"type":"public-key","alg":-7}],"authenticatorSelection":{"authenticatorAttachment":"platform","requireResidentKey":false,"userVerification":"required"},"attestation":"none","timeout":15000}
解决方案
我看到您正在调用组件navigator.credentials.create()
的. macOS 和 iOS Safari 都要求使用 Touch ID的 WebAuthn API 调用必须是“用户手势”的结果:<App />
componentDidMount()
不请自来的提示数量低得惊人。随着面向 Web 的 Face ID 和 Touch ID 的发布,情况有所不同。因此,Web 的 Face ID 和 Touch ID 需要用户手势才能发挥作用。(为了向后兼容,安全密钥不需要用户手势。)
有关更多指导,请参阅 Apple 对 WebAuthn 支持的介绍:https ://webkit.org/blog/11312/meet-face-id-and-touch-id-for-the-web/
如果您更新您的 React 代码以将调用逻辑移动navigator.credentials.create()
到按钮单击处理程序中,您将能够使用 Face ID。它需要您单击一个按钮来触发 WebAuthn,而不仅仅是加载页面,但这是在 Apple OS 上使用 WebAuthn 的现实。
推荐阅读
- python - 删除列表中的元组,然后将平均值分配给删除的元组
- python - 使用 seaborn 可视化缺失数据的出现频率
- jquery - Jquery .attr() 在 onclick 事件期间未读取我的“数据链接”html 值
- r - R - 引用矩阵中的值
- python - 使用部分原始文件名动态命名导入 Python 的 DataFrame
- java - 如何解决:javax.xml.transform.sax.SAXSource 无法转换为 java.io.Serializable [BonitaSoft]
- angular - 窗口打开功能有效但立即关闭新打开的窗口
- jquery - jQuery 在 ASP.NET Core 2.2 Razor 视图中不可用
- javascript - Codility CyclicRotation Javascript 解决方案:空数组返回错误
- c - C中的整数和浮点除法