无法从 webauthn 获取凭据(Chrome + Android)

bel*_*ban 8 javascript google-chrome webauthn

我正在尝试为网络应用程序设置 webauthn 凭据登录。我正在最新的 Android (Pixel 2) 和最新的 Android Chrome 上进行测试。

我可以使用函数 navigator.credentials.create({publicKey}) 创建并发送凭证对象。密钥是使用内部指纹传感器或更好的 android-safetynet 创建的。

当我想使用 navigator.credentials.get({publicKey}) 获取此密钥时,我总是收到错误:“NotAllowedError:操作超时或不允许。请参阅: https: //www.w3.org/TR/ webauthn-2/#sctn-privacy-considerations-client。” 到目前为止,我没有发现任何对这个错误有用的东西。

捕获错误的代码示例:

const base64Id = 'Ej_1cfBcad6TVO1choHVQl';
const bufferId = Buffer.from(base64Id, 'base64');

const randomChallenge = crypto.randomBytes(32);
const bufferChallenge = Buffer.from(randomChallenge, 'base64');

const options = {
  challenge: bufferChallenge,
  timeout: 60000,
  allowCredentials: [
    {
      transports: ['internal'],
      type: 'public-key',
      id: bufferId
    },
  ],
};

navigator.credentials
  .get({ publicKey: options })
  .then((credentialInfoAssertion) => {
    alert(credentialInfoAssertion.toString());
  })
  .catch((err) => {
    alert(err.toString());
  });
Run Code Online (Sandbox Code Playgroud)

调用 get credential 会导致错误,预期结果是获取凭证(就像我从 .create 方法获取的凭证一样)。

我使用 webauthn 测试了一些演示网站,它可以正常工作,因此浏览器支持没有问题。

谢谢