webauthn
Register and authenticate passkeys via the Credential Management / WebAuthn
API (navigator.credentials).
Import: @rtorcato/browser-common/webauthn
๐ MDN: Web Authentication API ยท ๐ caniuse: webauthn
createCredential/getCredential need a secure context and throw where Credential Management is unsupported โ guard with isWebAuthnAvailable().
Browser supportโ
| API | Chrome | Edge | Firefox | Safari | iOS Safari | Baseline |
|---|---|---|---|---|---|---|
PublicKeyCredential | โ 67+ | โ 18+ | โ 60+ [1] | โ 13+ | โ 13+ | Widely available |
CredentialsContainer.create | โ 60+ | โ 18+ | โ 60+ | โ 13+ | โ 13+ | Widely available |
- Firefox: Only supports USB U2F tokens.
โ
supported ยท โ partial ยท โ not supported ยท [n] see note. Generated from MDN browser-compat-data and web-features. caniuse: PublicKeyCredential ยท CredentialsContainer.create
Exampleโ
import {
isWebAuthnAvailable,
createCredential,
getCredential,
} from '@rtorcato/browser-common/webauthn'
if (isWebAuthnAvailable()) {
const credential = await createCredential({ publicKey })
const assertion = await getCredential({ publicKey })
}
Exportsโ
isWebAuthnAvailable()โ feature checkcreateCredential(options?)โ registers a new credential vianavigator.credentials.creategetCredential(options?)โ retrieves an existing credential vianavigator.credentials.get
See the API reference for full signatures.