Expand description
Passkeys for fastauth: WebAuthn registration and
sign-in, built on webauthn-rs. The routes and JSON match
Better Auth’s passkey plugin, so its passkeyClient works unchanged.
use fastauth_core::prelude::*;
use fastauth_plugin_passkey::{Passkey, PasskeyExt};
let auth: Auth<MemoryAdapter, (), plugins![Passkey]> = FastAuth::builder()
.secret(Secret::from_bytes(vec![1u8; 32]))
.base_url("https://acme.dk")
.database(MemoryAdapter::new())
.email_password(EmailPassword::default())
.plugin(Passkey::new().rp_name("Acme"))
.build()?;
let _passkeys = auth.passkey();Without the plugin registered, auth.passkey() doesn’t compile:
use fastauth_core::prelude::*;
use fastauth_plugin_passkey::PasskeyExt;
let auth: Auth<MemoryAdapter> = FastAuth::builder()
.secret(Secret::from_bytes(vec![1u8; 32]))
.base_url("https://acme.dk")
.database(MemoryAdapter::new())
.build()
.unwrap();
let _passkeys = auth.passkey();A signed-in user adds a passkey with generate-register-options then
verify-registration; anyone signs in with generate-authenticate-options then
verify-authentication. Each generate-* call stores its challenge server-side for five
minutes, in the verification table, and names it in a signed {prefix}.passkey cookie;
the matching verify-* call consumes it, so each challenge works once. Signing in runs the
other plugins’ sign-in gates with method "passkey", and checks and advances the
credential’s signature counter.
Re-exports§
pub use webauthn_rs;
Structs§
- Delete
Passkey POST /passkey/delete-passkey: deletes one of the signed-in user’s passkeys.- Delete
Passkey Input - Body of
/passkey/delete-passkey. - Generate
Authenticate Options GET /passkey/generate-authenticate-options: thePublicKeyCredentialRequestOptionsto pass tonavigator.credentials.get(). Signed out, any discoverable passkey for this site may answer; signed in, the options list the user’s passkeys.- Generate
Register Options GET /passkey/generate-register-options: thePublicKeyCredentialCreationOptionsto pass tonavigator.credentials.create(). Needs a fresh session. The user’s passkeys are excluded, so an authenticator can’t register twice.- Generate
Register Options Input - Query of
/passkey/generate-register-options. - List
User Passkeys GET /passkey/list-user-passkeys: the signed-in user’s passkeys.- Passkey
- The passkey plugin:
.plugin(Passkey::new()). - Passkey
Added - Emitted when a user registers a passkey.
- Passkey
Api - Manages a user’s passkeys without HTTP.
headersare the request’s: their cookies carry the session. Registering and signing in need a browser, so they go over HTTP. - Passkey
Deleted - Emitted when a user deletes one of their passkeys.
- Passkey
Row - A row of
passkey: one registered WebAuthn credential. The columns are Better Auth’s, in snake case, so a Better Auth passkey table carries over. - Passkey
View - A passkey as clients see it: Better Auth’s row, camelCase,
credentialIDincluded. - Register
Output - The new passkey; with
createSession, also the new session and the user. - Update
Passkey POST /passkey/update-passkey: renames one of the signed-in user’s passkeys.- Update
Passkey Input - Body of
/passkey/update-passkey. - Update
Passkey Output - Verify
Authentication POST /passkey/verify-authentication: verifies the assertion against the challenge fromgenerate-authenticate-optionsand the stored public key, checks and advances the signature counter, then signs the passkey’s user in through the sign-in gates (method"passkey").- Verify
Authentication Input - Body of
/passkey/verify-authentication. - Verify
Registration POST /passkey/verify-registration: verifies the authenticator’s attestation against the challenge fromgenerate-register-optionsand stores the passkey. Needs a fresh session, the same user’s.- Verify
Registration Input - Body of
/passkey/verify-registration.
Enums§
- Passkey
Error - Why a passkey request failed. Codes and statuses match Better Auth’s passkey plugin.
- Sign
InOutput - What a passkey sign-in answers.
Traits§
- Passkey
Ext auth.passkey(): the server API. Only compiles on anAuthwithPasskeyregistered.