PublicKeyCredential 无法序列化

Pay*_*erl 5 javascript json ecmascript-6 console.log webauthn

我正在 Angular 应用程序中实现 FIDO2(WebAuthn)。我已经获得了 PublicKeyCredentialCreationOptions 对象和 seccessfullt 寄存器。但打电话之后

let response = await navigator.credentials.create({'publicKey': myPublicKeyCredentialCreationOption })
Run Code Online (Sandbox Code Playgroud)

我尝试将响应发送到服务器。但是失败了。当我尝试使用浏览器中的对象查看时

console.log(JSON.stringify(response)) 
Run Code Online (Sandbox Code Playgroud)

我明白了

{}
Run Code Online (Sandbox Code Playgroud)

作为输出 (?..) 但在做时

console.log(response) 
Run Code Online (Sandbox Code Playgroud)

我在控制台中得到一个带有值的对象...该对象应该如何序列化以发送到服务器?

Raf*_*afe 6

PublicKeyCredential对象包含无法序列化为 JSON 的ArrayBuffer对象。您可以在 Angular 应用程序中对这些值进行 Base64 编码,然后在服务器上进行解码以获取相同的字节数组。存在一个完全可以为 WebAuthn 执行此操作的帮助程序库:https://github.com/github/webauthn-json