Quick start
From your application root, with a development deployment selected:http://localhost:5173 for a Vite app, http://localhost:3000 otherwise);
pass --web-server-url <origin> when the app is served elsewhere, and always
for a production deployment. The command:
- installs
@bijectionhq/library-auth: the copy pinned in your CLI release, else the matching version from npm (workspace:*inside the Bijection monorepo); - writes
bijection/auth.tswith passkeys and email codes, places it atauthin your app tree, and addsbijection/auth.settings.ts, which reads the site URL and your app’s origin; - generates the library’s signing and MAC keys and seals them on the
deployment (
auth.keys.signing,auth.keys.mac); the material never leaves the host; - registers the deployment’s own issuer,
<site URL>/auth, inbijection/sign-in.ts, with native renewal, OIDC back-channel logout and trusted verified email turned on.
src/main.tsx
/connections/callback too: the provider finishes
sign-in there and returns to the page that started it. Run bijection dev,
open the app and choose Sign in. A local deployment serves its site on
http://localhost:<port>, which browsers treat as secure, so passkeys work
there as they do on every hosted deployment. Email codes work too: a local
deployment’s code sender writes the code to its log
(bijection list sys.logs). Open the app on localhost as well (Vite’s default), not
127.0.0.1: a passkey belongs to a host name, and an IP address is never one.
Your users
Bijection Auth keeps its own records (sign-in methods, passkeys, codes, attempts) in private library tables that your functions cannot read. Your users live in your table.createUser runs in the same transaction that
records a newly proved sign-in and answers your fact’s ID:
bijection/auth.ts
profile is { name, email, emailVerified, phone, phoneVerified }, with
null for what the method did not supply. A failure in createUser leaves
nothing behind. onSignIn(ctx, { userId, method }) runs the same way on
every successful sign-in.
In any function, await auth.userOf(ctx) answers the signed-in caller’s user
ID, or null:
bijection/account.ts
person:… principal and never shows functions the provider’s subject. When a
sign-in completes, the callback carries a one-time claim next to the code;
the browser client, once signed in, redeems it with the sign-in’s PKCE
verifier (auth.session.bind) and that binds the person to its user. Only
the browser that started the sign-in holds the verifier, so a claim or code
taken from the redirect binds nothing. A person who has not bound, such as a
first sign-in from the CLI, is nobody’s user: userOf answers null until
that person signs in once in the browser.
Use the user ID for your relationships and business data. Use
roles, grants and labels for what the person may do: signing in
holds role.signedIn and nothing more.
Private per-user notes
Per-user privacy is a label family and a grant, not a filter on an owner field. Each author gets a member of anauthors family and the author role
under it; a notes table labelled with the family puts every note in its
author’s member, so the host refuses a read across authors. The code is the
same with any provider: the
Bijection Auth example
and the AuthKit example
share their notes.ts, access.ts and roles.ts. See Labels
for the model.
Sign-in methods
List the methods inmethods, each once. The sign-in page offers them in
that order.
Passkeys
passkey() registers and uses discoverable WebAuthn credentials (ES256 and
RS256), with user verification required and the origin and relying party
(the site’s host name) checked exactly. A sign count that goes backwards is
refused. A new passkey may carry an optional email, which stays unverified
until an email ceremony confirms it. Passkeys need a site with a host name:
every hosted deployment, and a local one on http://localhost:<port> (only
non-production deployments accept an HTTP issuer). A site on an IP address,
such as http://127.0.0.1, offers email codes instead.
Email codes and magic links
emailCode() sends a six-digit code that expires within ten minutes and
allows five tries. With link: true, the email also carries a one-use link
bound to the attempt and to the browser that asked for it. Opened in another
browser, it spends nothing and asks for the code on the device where sign-in
started. Codes and links share the same lifetime and rate limits. See
Email delivery.
GitHub, Google and Apple
These methods send the person to the provider and back to<site>/auth/attempt/<method>/callback, which you register with the
provider. Client IDs are public values; client secrets and Apple’s private
key are placed secret()s that only the host opens:
.p8 key file). Each prompt
has a non-interactive flag; see the reference.
- GitHub’s token exchange is a
captureoperation: the host seals GitHub’s access token as a bearer that only the profile request presents, and the flow retracts it once the profile is read. Only the verified primary email counts. - Google’s identity comes from its verified ID token, including
phone_numberandphone_number_verified. - Apple’s client secret is a short-lived JWT the host signs with your
es256key. Apple sends the person’s name only on the first sign-in; it reachescreateUserasprofile.name.
Email delivery
Choose how codes and links are delivered:-
emailCode()(optionallyemailCode({ from, replyTo })) renders a branded, accessible HTML and plain-text email and sends it through the library’s mail slot,auth.mail(send-mail@1). Code never says who sends it. Unbound, the host’s managed sender does; to use your own relay, bind it in the installation’s bindings file:Where the host offers no sender and the slot is unbound, deploy refuses withbindings.tsPlacementUnavailable(NotOffered), which names both fixes, rather than dropping codes silently. On a localhttp://localhostorhttp://127.0.0.1deployment, the code is written to the deployment log. -
A vendor named in code:
emailCode({ via: resend({ bearer, from }) })oremailCode({ via: postmark({ serverToken, from }) })renders the same email and submits it to that provider. The key is a placed secret: set it withbijection secret set. Use a sender address your mail provider has verified.bijection/auth.ts -
Your own code:
emailCode({ send })hands you(ctx, { email, code, url })in the transaction that accepts the request, so you can submit to your own target atomically with it.
bijection auth init --provider bijection --email-provider resend --email-from "Acme <sign-in@acme.example>"
writes a vendor delivery for you, with the sender in AUTH_EMAIL_FROM and the
key in a placed secret it asks for. Add --magic-link for links.
Which identity providers may sign people in is not placement: issuers are
trust facts changed by an audited trust act, never by a deploy
(switch providers).
The sign-in page
The deployment serves the sign-in page itself at<site>/auth/authorize. It
is server-rendered, mobile-first, light and dark, and accessible (labels,
focus, contrast, reduced motion, announced errors). Email codes work without
JavaScript, and the page is served with a strict content security policy.
Pass these options as branding to bijectionAuth:
#rgb or #rrggbb; text on the
accent is adjusted to meet WCAG AA contrast. A wrong value refuses at deploy,
not at sign-in. The same branding appears in sign-in emails.
To sign in inside your own app instead, set signInPage to the exact URL of
a page of your app, install @bijection/sign-in from ui.bijection.com, and
wire its callbacks to the helpers in @bijectionhq/library-auth/client:
fetchSignInMethods, passkeySignIn, passkeyRegister, sendEmailCode,
verifyEmailCode and startOAuth. Each takes { siteUrl, attempt } and
reports failures as AuthError with a stable code. Passkeys run on the
deployment site’s origin, so a page on another origin hands the passkey step to
the deployment’s page.
Accounts and recovery
Install@bijection/manage-account and @bijection/signed-in-devices from
ui.bijection.com and connect them to api<typeof App>().auth.session with
useWatch and useMutation from @bijectionhq/bijection/react. Passkeys
(add one on this device, rename, remove) and linked sign-in methods (add,
remove) come from the session functions below; the signed-in devices list
reads listSessions() and ends one with endSession(sessionId) from the
createAuthSession snapshot, which covers every device and CLI signed in to
the person’s account:
A person always keeps at least one way to sign in: removing the last one is
refused. Linking needs the person signed in and a fresh proof of the new
method. Two accounts with the same email are never linked automatically.
Adding a passkey on a new device is
linkStart({ method: "passkey" }).
Recovery. The sign-in page offers recovery to a person who lost their
passkey: they enter a verified email address of their account and the code
sent to it. The code signs in to the account that verified that address
(never one where the address was only typed with a passkey), and the page
offers to create a new passkey on this device before continuing. Keep
emailCode() beside passkey() (the scaffold does) so recovery is always
possible.
Sessions and lifecycle
After sign-in the session is Bijection’s native session, the same one every provider gets: a sender-bound access token (each request is signed with a browser key the page cannot export), renewed by the deployment within its idle and absolute lifetimes, revocable and audited. The issuer returns no refresh token: the source’snativeSessions: { renewal: "native" } lets the
deployment renew without calling it.
signOut()ends this browser’s session.signOut({ allSessions: true })ends every session of the person. A pending sign-out withdraws application access and retains its exact request. If the bearer expires, retry sign-out to check the original receipt and renew the credential if needed to finish. A temporary renewal refusal preserves that pending request. If sign-out could never be sent and renewal is unavailable, the browser clears its unusable session.listSessions()(on thecreateAuthSessionsnapshot from@bijectionhq/library-auth/client) lists the person’s live sessions, newest first:{ sessionId, current, issuer, client, createdAt, expiresAt, idleExpiresAt }, times in epoch milliseconds.endSession(sessionId)ends one of them (this browser’s is a sign-out). Install@bijection/signed-in-devicesfromui.bijection.comto render the list. Both use the deployment’s native session inventory (GET /api/bijection/identity/sessions, andPOST /api/bijection/identity/session/endwithsession), which every provider’s native sessions share;bijection auth sessionsshows the same list in the CLI.signIn({ reauthenticate: true })forces a fresh ceremony (OIDCmax_age=0);auth_timeis that ceremony’s time.await auth.endSessions(ctx, userId)in your mutation ends all of a user’s sessions.await auth.deleteUser(ctx, userId)also removes their sign-in methods and passkeys; delete your own user fact in the same mutation.
backChannelLogout: true). Check that the caller may manage the user first;
the example’s account.deleteMe lets people delete only themselves.
Owners and invitations
Declare the owner in the app’s founder roles and name the founder at installation creation. When nominated by email, the first matching verified app sign-in receives the role. A signed-in owner can useteam.invite to issue additional invitations.
Security model
- Same interfaces as any provider. The library is an OIDC issuer at
<site>/auth(discovery, authorization code with S256 PKCE, JWKS). The native layer verifies it like an external issuer. The library never writes native session, grant or membership state, and authorization never reads its tables. - Keys stay in the host. The RS256 signing key and the HMAC key are
secret({ alg })keys: functions ask the host to sign or MAC and never hold the material. Email codes and authorization codes are stored only as MACs and compared in constant time. - Private credential tables. Every Bijection Auth table (accounts,
passkeys, email codes, attempts, authorization codes, rate limits) is
declared
private: true. Your app places them when it placesauth, but only the library’s own functions read or write them: a function of your app that reads one is refusedLibraryTableReaderRequired, and one that writes one is refused at commit, whoever calls it (a signed-in user, a client or an administrator). Read accounts throughauth.userOf(ctx)and theauth.sessionentries. Any library can keep its tables private the same way. - Short, single-use credentials. Attempts expire after ten minutes; authorization codes after 60 seconds, spent on exchange; email codes within ten minutes, after at most five tries.
- Rate limits per attempt, per email address and per account, with the counters in a private table.
- Exact redirects. Only the registered
/connections/callbackURLs (and loopback CLI callbacks withcli: true) receive codes. There is no open redirect. - Honest assurance. The ID token’s
amrnames the ceremony that proved the sign-in, andauth_timeits time; PKCE verifiers are compared in constant time. - Hardened pages. A nonce-based content security policy, no framing
(
X-Frame-Options), no caching of ceremony replies, and refusals with stable codes and human messages (refusal codes). - No silent linking. A matching email never merges accounts.
- Sender-bound person binding. The claim that ties a signed-in person to
a user is single use, lasts ten minutes, is redeemable only after its code
was exchanged and only with the sign-in’s PKCE verifier. A person bound to
one user is never rebound to another (
AuthPersonBound).
Test your sign-in
The example ships an end-to-end suite you can copy. Playwright drives email codes, passkeys (with a virtual WebAuthn authenticator), renewal, sign-out and account deletion against a real deployment. See the example README.Switch to your own provider
Nothing in your app depends on Bijection Auth beyondauth.ts, the
auth.userOf(ctx) calls and the React provider:
- Add the new provider’s source to
bijection/sign-in.tsand its client adapter (for exampleauthkit()), keeping the Bijection Auth source during the move. - For each existing user, record the principal (
ctx.frame.as.id) the new provider’s sign-in opens. Use verified email only to find the candidate fact, and confirm the match (a sign-in with the old method, or an administrator). - Replace
auth.userOf(ctx)with a lookup through that association, and grant roles to the new principals. - Remove the
authsubtree, its source and@bijectionhq/library-auth.