Browser client.
One entry point with honest outcomes, step-up that retries once, and no session token in the page.
On this page
import { createAuthClient } from '@tensile-tools/auth-client'
const auth = createAuthClient()
const r = await auth.enter() // ok | no_passkey_or_cancelled | already_registered | unsupported | throttled | problem
await auth.fetch('/repos/x/secrets', { method: 'PUT', body, stepUpFirst: true })See client/README.md. Methods that take options take an object, for example confirmEmail({code}) and resetPassword({password}). In development, auth.WithDevTools() with authhttp.DevTools and the client’s mountDevTools let you make a session stale or switch to recovery mode in one click.
Use it
import { createAuthClient } from '@tensile-tools/auth-client'
const auth = createAuthClient()
const r = await auth.enter()
switch (r.outcome) {
case 'ok': break // signed in
case 'no_passkey_or_cancelled': showEntryOptions(); break // create one, use a phone, or a recovery code
case 'throttled': showWait(r.retryAfter); break
case 'problem': show(r.problem.title, r.problem.fix); break
case 'unsupported': showFallback(); break
}signIn,signUp({name}),addPasskey({label}), andstepUp({for})return the sameOutcome.signInWithPassword({email, password}),signUpWithPassword({email, password}),forgotPassword(email),stepUpWithPassword(password),changePassword,addPassword,removePassword,changeEmail,resendVerification, andpasswordStatuscall the email and password routes thatauthroutes.Mountserves withConfig.Passwords. A failed sign-in is always the samefactor_rejectedproblem. Use<input type="password">and allow paste.confirmEmail()andresetPassword({password})read the code from the link’s URL fragment (#code=…), which browsers don’t send to servers or inReferer, remove it from the address bar, and post it once. Build the link that way, for examplehttps://app.example/confirm#code=…. Both take an object: to pass a code you already have, callconfirmEmail({code})orresetPassword({code, password}), neverconfirmEmail(code). WhenconfirmEmailanswers theconfirm_sign_inproblem, call it again with{password}.enter()is one “Continue” button. It uses immediate mediation where the browser has it, so a person without a passkey goes straight to sign-up with no failed prompt.autofill()offers passkeys in an input withautocomplete="username webauthn". Any other ceremony cancels it first, which otherwise fails without a word.fetch(path, init)steps up when a response is astep_up_requiredorstronger_factor_requiredchallenge that a passkey can meet, for the challenge’s purpose if it has one, and retries once. It throws aProblemErrorfor any other refusal.syncPasskeys()calls the WebAuthn Signal API, so iCloud Keychain, Google Password Manager, and 1Password stop offering removed passkeys. A rejected sign-in never signals a passkey as unknown, because a rejection can mean an expired ceremony as well as a removed passkey.onSessionChange(fn)hears sign-in, sign-out, step-up, and a lost session from every tab throughBroadcastChannel.capabilities()reports platform authenticators, phone sign-in, autofill, PRF, and immediate mediation.freshUntilsays until when the session passes step-up checks, fromauthhttp.WithFreshHeader, andfetch(path, {stepUpFirst: true})confirms first when it has passed.approvals(),approval(id),approve(id), anddeny(id)read and decide the approvals agents ask the person for;approveruns a passkey ceremony whose signature covers the exact action.sessions(),revokeSession(id), andsignOutOthers()manage the session tree.activity({before})reads the person’s audit events and the chain state.recoverySignIns()andundoRecovery(session)back “That wasn’t me”.totpStatus()answers whether the authenticator app is on, locked, or not set up, andremoveTOTP()removes it.enrollTOTP(),confirmTOTP(code),generateRecoveryCodes(), andconfirmRecoveryCodes(code)set up two-step codes. Each answers anOutcome, and steps up first when the server asks.mountDevTools(client)shows the session and offers “Make stale” and “Recovery mode” againstauthhttp.DevTools, on a server withauth.WithDevToolsonly.deriveKey(prfOutput, purpose)turns a passkey’s PRF output into a non-extractable AES-GCM key, or'unsupported'.
Server routes
The client calls the routes in defaultEndpoints, which endpoints overrides. Each begin route answers the WebAuthn options that passkey.Passkeys returns ({"publicKey": …}); each finish route takes the credential JSON and answers JSON or nothing. Refusals must be problem details, as authhttp.Error writes them. The credentials route answers passkey.Passkeys.AcceptedCredentials, optionally with name and displayName.