Passkeys in a self-hosted identity server
How Ostiary handles passkeys: WebAuthn sign-in on your own domain, why the RP ID decides where they work, and the guards around adding one to an account.
Passwords are the weakest part of most sign-in pages, and passkeys are the most practical way to move past them. When you run your own identity provider, you also decide where those passkeys live. This post explains how Ostiary, a self-hosted identity provider built on Better Auth, handles passkeys, and the one decision to make before your users register any: the domain.
What a passkey is
The FIDO Alliance describes a passkey as a credential based on FIDO standards, stored on a phone, a computer or a hardware security key, that lets someone sign in with the same gesture they use to unlock the device: a fingerprint, a face, a PIN or a pattern.
On the web, a passkey is a public key credential used through the W3C Web Authentication API (WebAuthn). When someone registers one, their authenticator creates a key pair. The server keeps the public key; the private key stays with the authenticator. To sign in, the authenticator signs a fresh challenge from the server, and the server checks the signature with the public key it stored. There is no shared secret on the server to leak, and the credential only works on the site it was created for, so a look-alike page cannot use it. Our glossary entry sums up the vocabulary.
Passkeys in Ostiary
Ostiary uses Better Auth's passkey plugin. Both WebAuthn ceremonies, registration and authentication, run on Ostiary's own pages, never inside the applications that sign in through it.
Signing in
The sign-in page has a passkey button next to the email and password form. The identifier and password fields also carry autocomplete="username webauthn" and autocomplete="current-password webauthn". Where the browser supports conditional mediation (checked with isConditionalMediationAvailable(), from WebAuthn Level 3), Ostiary starts a passkey request in the background, so saved passkeys appear among the browser's autofill suggestions. Picking one signs the person in. Like the other methods, a passkey sign-in then follows the page's callbackURL, which Ostiary only accepts when it points to its own app or to a trusted origin.
Adding a passkey
People add passkeys from their account dashboard. Because a passkey is a new and lasting way into the account, Ostiary only accepts one from a sign-in made in the last 10 minutes. That window is measured from when the session was created, not from its last refresh: Better Auth's default freshness check counts from the refresh, which a stolen session cookie could trigger on its own. Connecting a social account follows the same rule, since it also adds a way to sign in.
An administrator impersonating an account to help its owner cannot add a passkey to it, nor connect a provider. The end-to-end test suite checks that the passkey registration endpoint answers 403 in that case.
The RP ID: decide your auth domain first
Every WebAuthn credential is bound to a relying party identifier, the RP ID. The specification is explicit: a public key credential can only be used for authentication with the same entity (as identified by RP ID) it was registered with. That binding is what makes passkeys resistant to phishing: a look-alike domain is a different RP ID, so the browser does not offer the credential there.
Ostiary sets the RP ID to the hostname of the auth app, and the expected origin to its scheme and host (passkey-options.ts). That base URL is AUTH_APP_URL when you set it. Otherwise it is BETTER_AUTH_URL, or what the platform provides: on Vercel, the project's production domain in production and the deployment's own URL in previews; locally, localhost. With AUTH_APP_URL=https://auth.example.com, every passkey is created for auth.example.com.
Two consequences follow for a self-hosted setup.
- Pick the final hostname before people register passkeys. Passkeys created while Ostiary ran on a temporary domain are tied to that domain's RP ID. If you later move it to
auth.example.com, those credentials no longer match, and people have to register new ones. If you start on a generated domain and add your own later, setAUTH_APP_URLto the final one before you invite anyone. - One domain serves every app. Because the ceremony always runs on Ostiary, a passkey registered once for
auth.example.comsigns its owner into every application connected through OpenID Connect. Your apps never handle WebAuthn: they receive tokens as usual. It is the single sign-on model, applied to passkeys.
Passkeys and two-factor authentication
Ostiary offers two-factor authentication with an authenticator app (TOTP, RFC 6238) and backup codes. For an account that has it, every way of signing in stops at the code step: passwords, emailed sign-in codes, social providers including Google One Tap, enterprise SSO and the email verification link. A device trusted for 30 days skips the step, whatever the method.
Passkeys are the exception. Ostiary treats them as already two factors: the device that holds the private key, and the fingerprint, face or PIN that unlocks it. Asking for a TOTP code after a passkey would add friction without adding a factor.
Next to the other sign-in methods
Passkeys sit alongside the other methods instead of replacing them:
- email and password, with email verification, and sign-in by username;
- a 6-digit code sent by email, which works across devices and inside OAuth sign-ins;
- social sign-in with Google, Apple, Microsoft, GitHub and more, turned on from the admin console;
- enterprise SSO over OIDC or SAML 2.0 for companies that bring their own identity provider, covered in SAML SSO and organizations for B2B apps.
An optional captcha (Cloudflare Turnstile, hCaptcha or reCAPTCHA v2) protects sign-up, password sign-in, password reset and sign-in codes. People can start with a password and add a passkey later, from a recent sign-in.
Passkeys and personal data
Ostiary's Your data export, for the GDPR rights of access and portability, lists each passkey with its name, device type, whether it is backed up, its transports, the authenticator model (AAGUID) and its creation date. It never contains the public key, the credential ID or the signature counter: they are useless outside the server and they identify the authenticator. Deleting an account deletes its passkeys with it. The account data guide maps every table, and the security notes list the other guards.
Try it
The live demo shows the sign-in screen with its passkey option. To host your own, the deployment guide and the Deploy section walk through the setup; set the final domain first. Then connect your apps over OpenID Connect, or see what else comes with a self-hosted, open-source Auth0 alternative.