# Needs and step-up

> Declare what an operation needs; the library decides, enforces, records, and explains each refusal.

From `docs/guide.md` in tensile-tools/tensile-auth at commit `e66760d` (v0.4.1-7-ge66760d). The HTML page is https://auth.tensile.tools/docs/guides/needs.

Declare what an operation needs, and let the library decide, enforce, audit, and explain:

**Go**
```go
need := auth.Need{Action: "secrets.edit", Assurance: auth.AssuranceMulti, Within: 10 * time.Minute, Human: true}
if err := svc.Require(ctx, principal, need); err != nil {
	authhttp.Error(w, r, err) // 403 with a challenge
	return
}
```

**Next.js**
```tsx
// app/security/page.tsx
import { auth } from '@/lib/auth'

export default async function Security() {
  const p = await auth.require({ action: 'security.view', human: true, within: '10m' })
  return <main><h1>Security</h1><p>Confirmed at {p.authenticated_at}</p></main>
}
```

The challenge names the need and lists only the factors this account has that would meet it:

```json
{"code": "step_up_required", "title": "Confirm it's you", "fix": "Confirm it's you with a passkey, then try again.",
 "challenge": {"action": "secrets.edit", "assurance": "multi", "within_seconds": 600, "human": true, "satisfy_with": ["passkey"]}}
```

`auth.WithNeeds` tightens any need by its action, the library's own included, and never loosens one. `svc.Meets` checks without recording, to decide what to show.

`Describe` and `authhttp.Error` are for errors from serving a request. Don't pass them setup errors, such as those from `passkey.New` or `mux.Check`: log those as they are.

To confirm once for one purpose only, step up with `svc.Elevate(ctx, principal, auth.For("secrets.edit", "repo:acme/api:prod"), proof)` and give the need a `Purpose`. A plain step-up doesn't count for it, and the elevation doesn't count for anything else.
