Occasional NotSupportedError exception using WebAuthn

主宰稳场 提交于 2020-06-01 06:48:25

问题


We use WebAuthn. Although, some devices throw exceptions NotSupportedError: The user agent does not support public key credentials.

Here is how we check if platform auth feature is available:

async function isWebAuthn() {
    return Boolean(
        navigator.credentials &&
        navigator.credentials.create &&
        navigator.credentials.get &&
        self.PublicKeyCredential &&
        self.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable &&
        await self.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()
    );
}

We see at least two devices which throw exceptions every time we try calling navigator.credentials.create().

  • Mozilla/5.0 (Linux; Android 9; ONEPLUS A3003) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.136 Mobile Safari/537.36
  • Mozilla/5.0 (Linux; Android 9; LG-H930) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.116 Mobile Safari/537.36

Here is the call:

await navigator.credentials.create({
    publicKey: {
        authenticatorSelection: {
            authenticatorAttachment: "platform",
            requireResidentKey: false,
            userVerification: "required"
        },
        challenge: challenge,
        rp: { id: document.domain, name: name },
        user: {
            id: id,
            name: name,
            displayName: displayName
        },
        pubKeyCredParams: [
            { type: "public-key", alg: -7 },
            { type: "public-key", alg: -257 }
        ]
    }
});

How to avoid browser throwing that exception?

来源:https://stackoverflow.com/questions/59939695/occasional-notsupportederror-exception-using-webauthn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!