使用带有电话触摸ID的导航凭据api

问题描述 投票:0回答:1

我正在尝试为webauthn api创建一个爱好项目。我有一个创建凭证的页面,它(正确)提示我们使用安全密钥。我想在我的Mac上使用我的touchid(在三星s9上)或touchid来创建证书(似乎无效)。 我是否需要做其他任何事情才能使其与触摸ID一起使用?

enter image description here

下面是创建证书的代码(我已经更改了域名)。

<script type="text/javascript">
  let randomStringFromServer = `sdflksdf934mnsdfsdfimlsndfbop1asd239dsfsdfkllkjsdf`;

  const publicKeyCredentialCreationOptions = {
    challenge: Uint8Array.from(randomStringFromServer, c =>
      c.charCodeAt(0)
    ),
    rp: {
      name: "Mr Tom",
      id: "helloworld.com"
    },
    user: {
      id: Uint8Array.from("UZSL85T9AFC", c => c.charCodeAt(0)),
      name: "[email protected]",
      displayName: "MrTom"
    },
    pubKeyCredParams: [{ alg: -7, type: "public-key" }],
    authenticatorSelection: {
      authenticatorAttachment: "cross-platform"
    },
    timeout: 60000,
    attestation: "direct"
  };

  const credential = await navigator.credentials.create({
    publicKey: publicKeyCredentialCreationOptions
  });

  console.log(credential);
</script>
public-key-encryption webauthn
1个回答
1
投票

控制此行为的重要位是:

authenticatorSelection: {
  authenticatorAttachment: "cross-platform"
}

这是告诉API您要使用外部设备作为身份验证器。如果您使用platform而不是cross-platform,则浏览器应遵循此原则,并尝试使用设备的内置功能。如果没有可用的平台验证器,您可能会立即返回错误-根据我的经验,是NotAllowedErrorNotSupportedError

© www.soinside.com 2019 - 2024. All rights reserved.