A simpler and safer sign-in
Tian Sen
Passkeys are a replacement for passwords. A password is something that can be remembered and typed, and a passkey is a secret stored on one’s devices, unlocked with biometrics.
Password requirements:
Passkeys are a significant use case for web authentication
navigator.credentials.get()
navigator.credentials.create()
let credential = await navigator.credentials.create({
publicKey: {
challenge: new Uint8Array([117, 61, 252, 231, 191, 241, ...]),
rp: { id: "passkey-demo.blog.tiansen.me", name: "Passkey Demo Online" },
user: {
id: new Uint8Array([79, 252, 83, 72, 214, 7, 89, 26]),
name: "[email protected]",
displayName: "[email protected]"
},
pubKeyCredParams: [
{type: "public-key", alg: -7}, // ES256
{type: "public-key", alg: -257} // RS256
]
}
});
let credential = await navigator.credentials.get({
publicKey: {
challenge: new Uint8Array([149, 66, 181, 87, 7, 203, ...]),
rpId: "passkey-demo.blog.tiansen.me",
allowCredentials: [{
type: "public-key",
id: new Uint8Array([64, 66, 35, 78, 168, 126, 174, ...])
},{
type: "public-key",
id: new Uint8Array([88, 86, 53, 87, 168, 226, 184, ...])
}]
}
});
Text
<input type="text" name="username" autocomplete="username webauthn" ...>
<script>
// Availability of `window.PublicKeyCredential` means WebAuthn is usable.
if (window.PublicKeyCredential &&
PublicKeyCredential.isConditionalMediationAvailable) {
// Check if conditional mediation is available.
const isCMA = await PublicKeyCredential.isConditionalMediationAvailable();
if (isCMA) {
const publicKeyCredentialRequestOptions = {
// Server generated challenge
challenge: new Uint8Array([123, 123, 123, 1, 123, ...]),
rpId: 'localhost',
};
const credential = await navigator.credentials.get({
publicKey: publicKeyCredentialRequestOptions,
// Specify 'conditional' to activate conditional UI
mediation: 'conditional'
});
}
}
</script>
Resistant to phishing, credential stuffing, and other remote attacks
Passkeys will be available wherever and whenever they need them.
Passkeys use your fingerprint or other biometric to log into your websites, just like unlocking your device
Resistant to phishing, credential stuffing, and other remote attacks