Project

bx-passkeys

WebAuthn passkeys for BoxLang: let people register a passkey and sign in with it, no password. Every browser answer is verified by webauthn4j, the library behind Spring Security's and Keycloak's passkey support. The module adds what webauthn4j leaves to you: one-time challenges, the options the browser needs, a credential store, and a sign counter that can't be raced. It has no routes of its own — you call four methods from your own handlers. The ColdBox edition is cbpasskeys.

Verified by webauthn4j

ES256, Ed25519 and RS256 — the three algorithms browsers actually use. The jars ship in libs/, with Jackson 3, whose packages don't clash with the Jackson 2 inside BoxLang.

Framework-agnostic

No routes. Challenges live in a session struct you pass in — session in a web app, req.session with boxlang-express.

Your credential store

A table-backed store (MSSQL, MySQL and Postgres scripts included) and an in-memory one ship with the module, or implement the five-method CredentialStore contract yourself.

Checked end to end

Single-use, expiring challenges; origin and rpId checks; signature counters that refuse cloned keys, with races between two sign-ins on one counter settled in the store.

Install

bashinstall-bx-module bx-passkeys

Requires BoxLang 1.19+ (Java 21). Attestation is "none": it trusts the key the authenticator hands over and doesn't check where the authenticator came from, which is what nearly every site wants. Attestation statements that do arrive are still checked for consistency.

Settings

json"modules": {
	"bxPasskeys": {
		"settings": {
			"rpId": "example.com",
			"rpName": "Example",
			"store": { "datasource": "app", "table": "passkey_credentials" }
		}
	}
}

Or pass them straight in: passkeyRelyingParty( { rpId: "example.com" } ). Without origins, sign-ins are allowed over https on the rpId itself, and plain http only on localhost. Subdomains are allowed only with allowSubdomains: true; leave it off if anyone else can serve pages on a subdomain.

Other settings: challengeSeconds (300), algorithms ([ -7, -8, -257 ]), userVerification ("preferred"), residentKey ("required"), maxPerUser (0, no limit) and sessionKey. A bad setting throws Passkeys.Configuration when the RelyingParty is built.

Registering a passkey

The user is already signed in some other way:

javascript// POST /passkeys/options
rp = passkeyRelyingParty()
return rp.registrationOptions( { id: user.id, name: user.email, displayName: user.name }, session )

// POST /passkeys        body = what createPasskey() returned
try {
	credential = rp.register( { id: user.id }, session, requestBody )
	return { id: credential.credentialId, name: credential.name }
} catch ( "Passkeys.Invalid" e ) {
	// 400, e.message is safe to show
}

register() returns the stored credential plus backupEligible and backedUp, so you can tell a synced passkey from a device-bound one. user.id is sent to the authenticator as UTF-8 bytes (at most 64), so don't put names or emails in it.

Signing in

javascript// POST /sign-in/passkey/options
return passkeyRelyingParty().signInOptions( session )

// POST /sign-in/passkey   body = what signWithPasskey() returned
try {
	result = passkeyRelyingParty().verify( session, requestBody )
	// result = { userId, credentialId, userVerified, backupEligible, backedUp, signCount, credential }
	// sign result.userId in; rotate the session id
} catch ( "Passkeys.Invalid" e ) {
	// 401
}

To re-confirm a user who is already signed in before a sensitive action, pass their id: signInOptions( session, user.id ). Only that user's passkeys are offered, and verify() refuses anyone else's.

In the browser

client/passkeys.js is a small ES module, with types in client/passkeys.d.ts. Copy it into your front end:

javascriptimport { createPasskey, signWithPasskey } from './passkeys.js'

const post = (path, body) => fetch(path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body ?? {}) }).then((r) => r.json())

// add a passkey
const registration = await createPasskey(await post('/passkeys/options'))
if (registration) await post('/passkeys', registration)

// sign in
const assertion = await signWithPasskey(await post('/sign-in/passkey/options'))
if (assertion) await post('/sign-in/passkey', assertion)

Both functions return null when the person closes the browser's sheet.

Credential stores

TableCredentialStore( { datasource, table } ) uses one table; create it from sql/mssql.sql, sql/mysql.sql or sql/postgres.sql, and keep the binary collations on credential_id and user_id. MemoryCredentialStore() is for tests and demos. To list or remove a user's passkeys on an account page, call the store directly: rp.getStore().listForUser( user.id ).

Going to production

  • Set rpId to your registrable domain and list origins exactly. Passkeys can't move to another rpId later.
  • Serve over HTTPS, rotate the session id after a passkey sign-in, and rate-limit the options and verify endpoints.
  • Keep a second way in until people have more than one passkey.
  • Upgrading from 0.2: registration now needs attestationObject (every browser and client/passkeys.js send it). Stored credentials keep working; the table is unchanged.

Not included

  • Attestation trust chains
  • Authenticator metadata (MDS)
  • WebAuthn extensions

Tests

TestBox specs, run in two BoxLang homes of their own: one plain and one with bx-compat-cfml loaded, so an installed copy of the module can't stand in for the checkout. examples/flow.bxs registers a passkey, signs in with it and shows a replay being refused, with a test authenticator standing in for the browser:

bashbox install
bash scripts/test.sh
boxlang --bx-home .tmp/bxhome examples/flow.bxs