# Kat's Lil Kitchen auth.md

You are an agent. Kat's Lil Kitchen (home sourdough bakery, Puriscal, Costa Rica) lets agents act for a customer: see their orders and prepare pickup orders. **Every order an agent places is held until the customer confirms it from an email link**, so always tell the customer to check their inbox.

Reading the menu, pickup dates and business info needs no credentials at all — use the public MCP server or API (see the end of this file).

## Step 1 — Discover

- Protected Resource Metadata: `GET https://katslilkitchen.com/.well-known/oauth-protected-resource`
- Authorization Server metadata (with the `agent_auth` block): `GET https://katslilkitchen.com/.well-known/oauth-authorization-server`

Protected endpoints answer `401` with `WWW-Authenticate: Bearer resource_metadata="…"` when you have no token.

## Step 2 — Pick a method

1. **You are an OAuth client** (ChatGPT, Claude, Cursor and other MCP connectors): use the standard authorization code flow with PKCE (S256). Register dynamically at the `registration_endpoint`, send the customer to the `authorization_endpoint`, where they sign in to their Kat's Lil Kitchen account and approve you.
2. **You have the customer's email** → `service_auth` (below). The customer signs in and types a 6-digit code you show them.
3. **You have nothing yet** → `anonymous`. You get a read-only credential (`menu:read`) and can ask the customer to claim you later.

`identity_assertion` (ID-JAG) is not enabled yet — no agent providers are on the trust list (`issuer_not_enabled`).

Before registering with an email, tell the customer what you will be able to do and get their OK:

- `orders:read` — See your orders and their status
- `orders:write` — Prepare orders for you — you confirm each one from your email before it is sent to Kat

## Step 3 — Register

### service_auth

```http
POST https://katslilkitchen.com/agent/identity
Content-Type: application/json

{ "type": "service_auth", "login_hint": "customer@example.com", "agent_name": "Your agent name" }
```

The response has a `claim_token` (keep it in memory only) and a `claim` block: `user_code`, `verification_uri`, `expires_in` (600), `interval` (5). `agent_name` is optional; the customer sees it on the confirmation page and in their list of connected assistants.

### anonymous

```http
POST https://katslilkitchen.com/agent/identity
Content-Type: application/json

{ "type": "anonymous", "agent_name": "Your agent name" }
```

Returns an `identity_assertion` (exchange it in Step 5 for a `menu:read` token) and a `claim_token`. To act for a customer, start a claim:

```http
POST https://katslilkitchen.com/agent/identity/claim
Content-Type: application/json

{ "claim_token": "clm_…", "email": "customer@example.com" }
```

The `claim_attempt` block in the response has the same shape as `claim` above. Call this again with the same values for a fresh code if one expires (`410 claim_expired` means start over).

## Step 4 — Claim ceremony

Send the customer one message:

> Open this link, sign in to Kat's Lil Kitchen (or create an account with the same email), and enter this code: **123456**
> <verification_uri>

Then poll every `interval` seconds:

```http
POST https://katslilkitchen.com/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=urn:workos:agent-auth:grant-type:claim&claim_token=<clm_…>
```

`authorization_pending` → keep waiting. `slow_down` → poll less often. `expired_token` → get a new code with `/agent/identity/claim`. On success you get `access_token` (1 hour), `scope`, and an `identity_assertion` (30 days) for refreshing.

## Step 5 — Exchange the assertion

```http
POST https://katslilkitchen.com/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=<identity_assertion>
```

Use this whenever the access_token expires. `invalid_grant` means the customer removed your access or the registration expired: start again at Step 3.

## Step 6 — Use the access_token

Send `Authorization: Bearer <access_token>` to any of:

- MCP (Streamable HTTP): `https://katslilkitchen.com/mcp/account` — tools `place_order`, `my_orders`, `cancel_pending_order` plus all public tools
- A2A (JSON-RPC): `https://katslilkitchen.com/a2a` — agent card at `https://katslilkitchen.com/.well-known/agent-card.json`
- REST: `GET https://katslilkitchen.com/api/agent/orders`, `POST https://katslilkitchen.com/api/agent/orders` — described in `https://katslilkitchen.com/openapi.json`

## Revocation

- You: `POST https://katslilkitchen.com/oauth/revoke` with `token=<access_token or refresh_token>` (form-encoded). Always 200.
- The customer can remove your access at any time from their profile page ("Connected AI assistants"). Your next token exchange then returns `invalid_grant`.

## Errors at /agent/identity

| Code | Meaning |
| --- | --- |
| `invalid_login_hint` | `login_hint` is not an email address |
| `issuer_not_enabled` | ID-JAG is not accepted yet |
| `invalid_request` | Bad body |
| `invalid_claim_token` / `claim_expired` / `claimed_or_in_flight` | At `/agent/identity/claim` |
| `rate_limited` (429) | Back off |

## Public, no credentials needed

- MCP: `https://katslilkitchen.com/mcp` (menu, pickup dates, business info, blog)
- Agent skill: `https://katslilkitchen.com/.well-known/agent-skills/index.json`
- Site guide: `https://katslilkitchen.com/llms.txt`
