client

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2026 License: Apache-2.0, Apache-2.0 Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

@tensile-tools/auth-client

The browser side of tensile-auth: a framework-free TypeScript module with no dependencies. It runs passkey ceremonies with outcomes a person can act on, reads every refusal as one problem shape, steps up when a request needs it, keeps password managers in sync, and keeps tabs in step. It never holds a session token: sessions stay in HttpOnly cookies.

It is versioned with the Go library:

npm install @tensile-tools/auth-client

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}), and stepUp({for}) return the same Outcome.
  • signInWithPassword({email, password}), signUpWithPassword({email, password}), forgotPassword(email), stepUpWithPassword(password), changePassword, addPassword, removePassword, changeEmail, resendVerification, and passwordStatus call the email and password routes that authroutes.Mount serves with Config.Passwords. A failed sign-in is always the same factor_rejected problem. Use <input type="password"> and allow paste.
  • confirmEmail() and resetPassword({password}) read the code from the link's URL fragment (#code=…), which browsers don't send to servers or in Referer, remove it from the address bar, and post it once. Build the link that way, for example https://app.example/confirm#code=…. Both take an object: to pass a code you already have, call confirmEmail({code}) or resetPassword({code, password}), never confirmEmail(code). When confirmEmail answers the confirm_sign_in problem, 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 with autocomplete="username webauthn". Any other ceremony cancels it first, which otherwise fails without a word.
  • fetch(path, init) steps up when a response is a step_up_required or stronger_factor_required challenge that a passkey can meet, for the challenge's purpose if it has one, and retries once. It throws a ProblemError for 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 through BroadcastChannel.
  • capabilities() reports platform authenticators, phone sign-in, autofill, PRF, and immediate mediation.
  • freshUntil says until when the session passes step-up checks, from authhttp.WithFreshHeader, and fetch(path, {stepUpFirst: true}) confirms first when it has passed.
  • approvals(), approval(id), approve(id), and deny(id) read and decide the approvals agents ask the person for; approve runs a passkey ceremony whose signature covers the exact action. sessions(), revokeSession(id), and signOutOthers() manage the session tree. activity({before}) reads the person's audit events and the chain state. recoverySignIns() and undoRecovery(session) back "That wasn't me". totpStatus() answers whether the authenticator app is on, locked, or not set up, and removeTOTP() removes it. enrollTOTP(), confirmTOTP(code), generateRecoveryCodes(), and confirmRecoveryCodes(code) set up two-step codes. Each answers an Outcome, and steps up first when the server asks.
  • mountDevTools(client) shows the session and offers "Make stale" and "Recovery mode" against authhttp.DevTools, on a server with auth.WithDevTools only.
  • deriveKey(prfOutput, purpose) turns a passkey's PRF output into a non-extractable AES-GCM key, or 'unsupported'.

Elements

The package also holds drop-in sign-in and account screens as Web Components: <tensile-sign-in>, <tensile-sign-up>, <tensile-step-up>, <tensile-approval>, <tensile-approvals>, <tensile-sessions>, <tensile-wasnt-me>, <tensile-activity>, <tensile-two-step>, and <tensile-recovery-codes>. Import /auth/client/elements/index.js to define them. Their options, events, and theming are in src/elements/.

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.

Contents

Name What it holds
src/ The TypeScript source
test/ The tests, which run with Node's test runner
dist/ The compiled ES modules and type declarations, built from src/ and committed, and dist/fonts/, the fonts the elements bundle
embed.go Package client, which embeds the compiled modules and the fonts so a Go server serves the client without Node
package.json, package-lock.json The package and its development dependencies
tsconfig.json, tsconfig.build.json The TypeScript settings for the type check and for the build

Check it

To type-check and test the client, run just client. It needs Node 22.18 or later, which runs TypeScript without a build step.

Documentation

Overview

Package client embeds the compiled browser client, so a Go server can serve it without Node: authroutes.Mount serves it under /auth/client/, and a page imports it with

import { createAuthClient } from '/auth/client/index.js'

and the elements with

<script type="module" src="/auth/client/elements/index.js"></script>

The TypeScript source is in src/; `just client` rebuilds dist/ and fails when it is out of date.

Index

Constants

This section is empty.

Variables

View Source
var FS = must(fs.Sub(dist, "dist"))

FS holds the compiled ES modules: index.js and the files it imports; elements/index.js, which defines the elements; and fonts/, the fonts the elements use by default, with their licenses.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL