# Drop-in elements

> Framework-free Web Components for sign-in, step-up, approvals, sessions, and activity, served with no build step.

From `docs/guide.md`, `skills/tensile-auth/SKILL.md`, `client/src/elements/README.md` in tensile-tools/tensile-auth at commit `e66760d` (v0.4.1-7-ge66760d). The HTML page is https://auth.tensile.tools/docs/guides/elements.

The elements are drop-in sign-in and account screens: framework-free Web Components built on the browser client, which `authroutes.Mount` serves under `/auth/client/elements/`. Use them instead of hand-written pages:

```html
<tensile-sign-in redirect="/"></tensile-sign-in>
<script type="module">
  import { configure } from '/auth/client/elements/index.js'
  configure({ appName: 'Acme', theme: 'auto', accent: '#7c4dff' })
  document.addEventListener('signed-in', e => console.log(e.detail))
</script>
```

| Element | Use it for |
|---|---|
| `<tensile-sign-in>`, `<tensile-sign-up>` | Sign-in and sign-up, with passkeys, email and password, TOTP, and recovery codes |
| `<tensile-step-up>` | "Confirm it's you" before a sensitive action |
| `<tensile-approval approval-id="…">` | The page an approval's `url` opens: the person approves the exact action with a passkey |
| `<tensile-approvals>` | The person's inbox of requests from their agents |
| `<tensile-sessions>` | Where the person is signed in, and the agents under each device |
| `<tensile-activity>` | The person's audit log and whether it matches its hash chain |
| `<tensile-wasnt-me>` | Undoing a sign-in with a recovery code |
| `<tensile-two-step>`, `<tensile-recovery-codes>` | The authenticator app, with its status, setup, replace, and remove, and recovery codes |

The account elements call routes that `Mount` serves for the signed-in person only, and that refuse agents: `GET /auth/approvals`, `/auth/approvals/{id}` with `begin`, `finish`, and `deny`, `GET /auth/sessions` with `revoke` and `revoke-others`, `GET /auth/activity`, and, with `Config.Recovery`, `GET /auth/recovery/sign-ins` and `POST /auth/recovery/undo`. A session in recovery mode can revoke only itself. The activity route checks the whole audit chain at most once a minute, in the background, and answers `verified`, `tampered`, `unknown`, or `unavailable`.

Set options as attributes, properties, a `config` object, or `configure()`; override any text by its key; theme with `--tensile-*` custom properties and `::part()`. The elements bundle Geist and Inter, and `font: "system"` loads no font. See [the elements' README](/docs/reference/elements) for every option and event, and `examples/agents` for an app that uses them.

## Build an account page

The elements are framework-free Web Components that handle every outcome, focus, and the live region. Import `index.js` once to define them all:

```html
<script type="module" src="/auth/client/elements/index.js"></script>
<tensile-sessions></tensile-sessions>
<tensile-two-step></tensile-two-step>
<tensile-step-up subject="Ravi Patel" action="to remove"></tensile-step-up>
<script type="module">
  document.addEventListener('revoked', e => console.log('revoked', e.detail))
</script>
```

- Sign-in: `<tensile-sign-in>` and `<tensile-sign-up>`.
- Account page: `<tensile-sessions>`, `<tensile-activity>`, `<tensile-approvals>`, `<tensile-wasnt-me>`, `<tensile-two-step>`, and `<tensile-recovery-codes>`.
- Approvals: `<tensile-approval approval-id="…">` at the path that `auth.WithApprovalURL` names.
- Before a sensitive action: `<tensile-step-up>`.

Set options with `configure({appName, methods, theme, accent, text})`, a property, or an attribute, and theme them with `--tensile-*` properties and `::part()`. Each element dispatches DOM events, such as `signed-in`, `approved`, and `revoked`. Behind the SDK's proxy, the same path works, because the server serves the client under `/auth/client/`. Every option and event is in `client/src/elements/README.md`.

## Accessibility

- Every control has a label, and every element moves focus to its headline or first field when its state changes. Loading doesn't move focus.
- Errors use `role="alert"`, and other changes are announced through a polite live region.
- The elements respect `prefers-reduced-motion`, and the dark theme meets the same contrast as the light one.

## Security

- When the session ends, by sign-out, expiry, or a revocation in any tab, every element that shows the person's data or secrets drops it at once. It fetches nothing until the next sign-in, and then loads once. `<tensile-wasnt-me>` hides instead.
- The elements never see a session token: the client keeps sessions in `HttpOnly` cookies.
- `redirect`, `sign-up-href`, and `sign-in-href` are followed only when they are on the page's own origin.
- `return_to` is followed only when it is a relative path on the page's own origin: one leading `/` that isn't followed by `/` or `\`, with no scheme, host, fragment, backslash, space, or control character, no `.` or `..` segment, plain or percent-encoded, and at most 2,048 characters. `authhttp.SafeReturnTo` applies the same rule on the server.
- The styles are constructed style sheets, so the elements work under a Content-Security-Policy without `'unsafe-inline'`.
