This page demonstrates the WebAuthn API for passkey-based authentication without using any external libraries.
Note: Your credential will be saved in this browser's session storage. Clearing your browser data or closing the window will require you to register again.
Choose your registration method:
WebAuthn supports two types of credential storage models:
// Standard registration
{
challenge: new Uint8Array([...]),
rp: {
name: "WebAuthn Demo",
id: window.location.hostname
},
user: {
id: new Uint8Array([...]),
name: username,
displayName: username
},
pubKeyCredParams: [
{ type: "public-key", alg: -7 }
],
authenticatorSelection: {
userVerification: "preferred"
}
}
// Resident key registration
{
challenge: new Uint8Array([...]),
rp: {
name: "WebAuthn Demo",
id: window.location.hostname
},
user: {
id: new Uint8Array([...]),
name: username,
displayName: username
},
pubKeyCredParams: [
{ type: "public-key", alg: -7 }
],
authenticatorSelection: {
requireResidentKey: true,
residentKey: "required",
userVerification: "preferred"
}
}
With resident keys, you can login without a username:
// Standard login
{
challenge: new Uint8Array([...]),
rpId: window.location.hostname,
allowCredentials: [{
id: storedCredentialId,
type: 'public-key'
}],
userVerification: "preferred"
}
// Resident key login
{
challenge: new Uint8Array([...]),
rpId: window.location.hostname,
// No allowCredentials needed!
userVerification: "preferred"
}