4

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

唯一的依赖是cbor.jsjs-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...

我想不通。你知道有什么问题吗?谢谢!

4

2 回答 2

7

I had the same problem, and the cause was that some of the pieces of data sent from the server in the response from /register/begin must be formatted as byte strings rather than unicode strings. In particular, I've found that the user_id and the credential ids have to be byte strings - assuming that you are also following Yubico's example in the server, implemented in python 3.

Also of note is that in this case I've found Firefox's error messages much more helpful than chome's.

于 2019-01-25T10:59:08.060 回答
1

我也有这个问题。我最终使用 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,
          ...
于 2021-03-24T17:31:21.980 回答