Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';无法理解JavaScript中的WebAuthn API错误_Javascript_Django_Yubico_Cbor_Webauthn - Fatal编程技术网

Can';无法理解JavaScript中的WebAuthn API错误

Can';无法理解JavaScript中的WebAuthn API错误,javascript,django,yubico,cbor,webauthn,Javascript,Django,Yubico,Cbor,Webauthn,我目前正在为Django构建一个AJAX注册端点,以允许FIDO2身份验证(物理硬件密钥登录)。这来自以下示例/文档 唯一的依赖项是cbor.js和js cookie。目前服务器端的一切都正常工作,但是,在调用navigator.credentials.create方法时,我一直遇到这个JavaScript错误 TypeError: Failed to execute 'create' on 'CredentialsContainer': The provided value is not o

我目前正在为Django构建一个AJAX注册端点,以允许FIDO2身份验证(物理硬件密钥登录)。这来自以下示例/文档

唯一的依赖项是
cbor.js
js cookie
。目前服务器端的一切都正常工作,但是,在调用
navigator.credentials.create
方法时,我一直遇到这个JavaScript错误

TypeError: Failed to execute 'create' on 
'CredentialsContainer': The provided value is not of 
type '(ArrayBuffer or ArrayBufferView)'
守则:

var csrftoken = Cookies.get('csrftoken');
fetch('/register/begin', {
    method: 'POST',
    headers: {
        'X-CSRFToken': csrftoken
    }
}).then(function(response) {
    if(response.ok) {
        return response.arrayBuffer();
    }
    throw new Error('Error getting registration data!');

}).then(CBOR.decode).then(function(options) {
    console.log(options)
    //This line is not working
    return navigator.credentials.create(options);
//More code... complete registration...

我想不出来。你知道怎么了吗?谢谢

我也遇到了同样的问题,原因是在/register/begin的响应中从服务器发送的一些数据必须格式化为字节字符串,而不是unicode字符串。特别是,我发现用户id和凭证id必须是字节字符串——假设您在服务器中也遵循Yubico的示例,该示例是用python 3实现的


同样值得注意的是,在本例中,我发现Firefox的错误消息比chome的更有用。

我也遇到了这个问题。我最终使用TextEncoder类对挑战和用户id进行编码

        const enc = new TextEncoder();     
        const createCredentialOptions: CredentialCreationOptions = {
        publicKey: {
          rp: rp,
          challenge: enc.encode(challenge),
          user: {
            id: enc.encode(user.id),
            name: user.name,
            displayName: user.displayName
          },
          pubKeyCredParams: pubKeyCredParams,
          ...
是的