Skip to main content

Crate fastauth_plugin_passkey

Crate fastauth_plugin_passkey 

Source
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_base64(&Secret::generate()))
    .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; with Passkey::sign_up, a signed-out visitor does the same and the passkey creates their user. 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. A user claimed by proof of their email (Internal::claim_user) loses the passkeys registered before the proof, inside the claim’s transaction.

Re-exports§

pub use webauthn_rs;

Structs§

DeletePasskey
POST /passkey/delete-passkey: deletes one of the signed-in user’s passkeys.
DeletePasskeyInput
Body of /passkey/delete-passkey.
GenerateAuthenticateOptions
GET /passkey/generate-authenticate-options: the PublicKeyCredentialRequestOptions to pass to navigator.credentials.get(). Signed out, any discoverable passkey for this site may answer; signed in, the options list the user’s passkeys.
GenerateRegisterOptions
GET /passkey/generate-register-options: the PublicKeyCredentialCreationOptions to pass to navigator.credentials.create(). Needs a fresh session that may mint credentials (see registering_session): 401 without one, 403 SESSION_NOT_FRESH with an old or ephemeral one. The user’s passkeys are excluded, so an authenticator can’t register twice. Signed out, with Passkey::sign_up on, its resolver names the user the passkey will create.
GenerateRegisterOptionsInput
Query of /passkey/generate-register-options.
ListUserPasskeys
GET /passkey/list-user-passkeys: the signed-in user’s passkeys.
Passkey
The passkey plugin: .plugin(Passkey::new()).
PasskeyAdded
Emitted when a user registers a passkey.
PasskeyApi
Manages a user’s passkeys without HTTP. headers are the request’s: their cookies carry the session. Registering and signing in need a browser, so they go over HTTP.
PasskeyDeleted
Emitted when a user deletes one of their passkeys.
PasskeyRow
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.
PasskeySignUp
A signed-out registration asking for a user: what Passkey::sign_up’s resolver gets.
PasskeyUser
The user a passkey-first registration creates.
PasskeyView
A passkey as clients see it: Better Auth’s row, camelCase, credentialID included.
RegisterOutput
The new passkey; with createSession, also the new session and the user, or for a passkey-first sign-up a sign-in gate’s answer ({"twoFactorRedirect": true}) instead.
UpdatePasskey
POST /passkey/update-passkey: renames one of the signed-in user’s passkeys.
UpdatePasskeyInput
Body of /passkey/update-passkey.
UpdatePasskeyOutput
VerifyAuthentication
POST /passkey/verify-authentication: verifies the assertion against the challenge from generate-authenticate-options and the stored public key, checks and advances the signature counter, then signs the passkey’s user in through the sign-in gates (method "passkey").
VerifyAuthenticationInput
Body of /passkey/verify-authentication.
VerifyRegistration
POST /passkey/verify-registration: verifies the authenticator’s attestation against the challenge from generate-register-options and stores the passkey. Needs the session generate-register-options needed, the same user’s. A passkey-first sign-up’s challenge only verifies signed out, and creates its user here.
VerifyRegistrationInput
Body of /passkey/verify-registration.

Enums§

PasskeyError
Why a passkey request failed. Codes and statuses match Better Auth’s passkey plugin.
SignInOutput
What a passkey sign-in answers.

Traits§

PasskeyExt
auth.passkey(): the server API. Only compiles on an Auth with Passkey registered.