Skip to main content

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โ€‹

APIChromeEdgeFirefoxSafariiOS SafariBaseline
PublicKeyCredentialโœ… 67+โœ… 18+โœ… 60+ [1]โœ… 13+โœ… 13+Widely available
CredentialsContainer.createโœ… 60+โœ… 18+โœ… 60+โœ… 13+โœ… 13+Widely available
  1. 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 check
  • createCredential(options?) โ€” registers a new credential via navigator.credentials.create
  • getCredential(options?) โ€” retrieves an existing credential via navigator.credentials.get

See the API reference for full signatures.