Authentication
Passkeys
Your application's people sign in with a fingerprint, a face or a security key instead of a password. A passkey can also stand in for the authenticator code after a password.
A passkey is a pair of keys made on the person's device for your site. The private half never leaves the device. Rezin Core keeps only the public half, and checks each sign-in against it.
Setting it up
Sign-in, Passkeys.
| Setting | What it is |
|---|---|
| Let people make and use passkeys | Off until you switch it on. It needs the project's site address to be set first. |
| Checking the person | Whether the device must check who is holding it (fingerprint, face or PIN) each time: always, when the device can, or not asked. |
| The site passkeys belong to | Empty means the host of your site address, such as app.example.com. Give a domain above it, such as example.com, if several parts of your site should share passkeys. |
A passkey works only on the site it was made for. Once passkeys exist, the site cannot be changed without removing them.
The page your code runs on must be one of the project's listed addresses (the site address or a redirect address), and its host must be the passkeys' site or under it. Anything else is refused.
The calls
Every call takes your project's key in the apikey header. Calls for a signed-in account also take its token as Authorization: Bearer ….
| Call | Who | What it does |
|---|---|---|
POST /v1/auth/passkeys/register/start | signed in | Answers the options to hand to the browser. |
POST /v1/auth/passkeys/register/finish | signed in | Takes what the browser made: { credential, name? }. Answers 201 with the passkey's id. |
GET /v1/auth/passkeys | signed in | The account's passkeys: name, when made, when last used. |
PATCH /v1/auth/passkeys/:id | signed in | Rename one: { name }. |
DELETE /v1/auth/passkeys/:id | signed in | Remove one. |
POST /v1/auth/passkeys/signin/start | anyone | Answers the options for signing in. It names no account. |
POST /v1/auth/passkeys/signin/finish | anyone | Takes the browser's answer: { credential, secondStepCode? }. Answers a session, like any other sign-in. |
POST /v1/auth/passkeys/second/start | anyone | { email }. Options for using a passkey as the second step after a password. |
Byte values travel as base64url text, in both directions.
An account can hold up to 10 passkeys. A question from a start call can be answered once, within five minutes.
In the browser
Add a passkey to the signed-in account:
const b64 = (buf) => btoa(String.fromCharCode(...new Uint8Array(buf))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
const bytes = (text) => Uint8Array.from(atob(text.replace(/-/g, '+').replace(/_/g, '/')), (c) => c.charCodeAt(0));
const api = (path, body, token) => fetch(`https://api.rezincore.com${path}`, {
method: 'POST',
headers: { apikey: PUBLISHABLE_KEY, 'content-type': 'application/json', ...(token ? { authorization: `Bearer ${token}` } : {}) },
body: JSON.stringify(body ?? {}),
}).then(async (r) => ({ status: r.status, ...(await r.json()) }));
async function addPasskey(token) {
const { publicKey } = await api('/v1/auth/passkeys/register/start', {}, token);
const made = await navigator.credentials.create({ publicKey: {
...publicKey,
challenge: bytes(publicKey.challenge),
user: { ...publicKey.user, id: bytes(publicKey.user.id) },
excludeCredentials: publicKey.excludeCredentials.map((c) => ({ ...c, id: bytes(c.id) })),
} });
return api('/v1/auth/passkeys/register/finish', { name: 'This device', credential: {
id: made.id,
response: {
clientDataJSON: b64(made.response.clientDataJSON),
attestationObject: b64(made.response.attestationObject),
transports: made.response.getTransports?.() ?? [],
},
} }, token);
}
Sign in with a passkey:
const answerOf = (got) => ({
id: got.id,
response: {
clientDataJSON: b64(got.response.clientDataJSON),
authenticatorData: b64(got.response.authenticatorData),
signature: b64(got.response.signature),
},
});
async function signInWithPasskey() {
const { publicKey } = await api('/v1/auth/passkeys/signin/start');
const got = await navigator.credentials.get({ publicKey: { ...publicKey, challenge: bytes(publicKey.challenge) } });
const session = await api('/v1/auth/passkeys/signin/finish', { credential: answerOf(got) });
// session.token is the account's token, as after any sign-in.
return session;
}
The device shows the passkeys it holds for your site and the person picks one. Your page never needs to ask for an email address first.
With the authenticator app
A passkey that checked the person stands as both steps: nothing more is asked.
A passkey that did not check the person is one step. If the account has an authenticator app, signin/finish answers 401 with code_required. Send the same credential again with the code as secondStepCode.
As the second step after a password
When POST /v1/auth/signin answers code_required, the person can use a passkey in place of the code:
async function passwordThenPasskey(email, password) {
const { publicKey } = await api('/v1/auth/passkeys/second/start', { email });
const got = await navigator.credentials.get({ publicKey: {
...publicKey,
challenge: bytes(publicKey.challenge),
allowCredentials: publicKey.allowCredentials.map((c) => ({ ...c, id: bytes(c.id) })),
} });
return api('/v1/auth/signin', { email, password, passkey: answerOf(got) });
}
second/start answers the same shape for an address with no account or no passkey, so it cannot be used to find out who has one.
What is refused
Every refusal answers 401 with bad_passkey and the same message, whatever the reason. The reason is written to the project's sign-in record.
| Reason in the record | What happened |
|---|---|
wrong_origin | The page is not at one of the project's listed addresses, or not under the passkeys' site. |
wrong_site | The passkey was made for a different site. |
wrong_challenge | The answer was not made for a question this project asked, or the question ran out or was already answered. |
not_verified | The project requires the device to check the person and it did not. |
bad_signature | The answer was not signed by the passkey on record. |
counter | The passkey's use counter did not move forward, which can mean the key was copied. |
A wrong signature or a counter that went backwards counts toward the account's lockout, like a wrong password.
Other answers: 403 method_off when the project does not use passkeys, 409 not_configured when it has no site address, 409 too_many at 10 passkeys, 409 already_added when the passkey is already on an account, and 400 unsupported_key for a kind of key that is not taken.
What is supported
- Keys of three kinds: ES256, RS256 and Ed25519.
- Passkeys kept on the device or in a synced store, and security keys.
- The maker's certificate (attestation) is not asked for and not checked.
In the console
Sign-in, Accounts, then one account: its passkeys are listed with when each was made and last used, and a member who may change the project can remove one. Only the public half exists on the server, so there is nothing secret to show.