# AI app sign-in (/docs/developers/oauth)

Todoku is its own OAuth 2.1 server. The person signs one wallet message on todokupay.xyz; the AI app gets a token for /api/mcp that can read your orders and make pay links in your name, never pay.

| Endpoint | Path |
| --- | --- |
| Protected resource metadata (RFC 9728) | `/.well-known/oauth-protected-resource/api/mcp` |
| Authorization server metadata (RFC 8414) | `/.well-known/oauth-authorization-server` |
| Authorize | `/oauth/authorize` → the consent page `/oauth/connect` |
| Token | `POST /api/oauth/token` |
| Register (RFC 7591) | `POST /api/oauth/register` |
| Revoke (RFC 7009) | `POST /api/oauth/revoke` |

## The flow [#the-flow]

1. A personal tool answers 401. The app reads the resource metadata, then the server metadata.
2. **Client**: apps with a client metadata document (CIMD) from claude.ai, claude.com or chatgpt.com are fetched and trusted by host; any other app registers itself (dynamic registration) and is shown as "(unverified)".
3. **Authorize**: code flow only, PKCE S256 only, the `resource` must be `/api/mcp`, scope `account`. Todoku's consent page names the app and where it sends you back.
4. **Consent**: the wallet signs one sign-in message that names the app and says it can't move money. The page checks the request's origin and a cookie set for that one request.
5. **Tokens**: a single-use code (60 seconds) for an access token (1 hour) and a refresh token (30 days, replaced on every use). Reusing a code, or an old refresh token after a 30-second grace, revokes the whole grant. Only SHA-256 hashes of tokens are stored.

## The rules [#the-rules]

- The consent page can't be framed by another site.
- A redirect must match exactly; a loopback address may use any port.
- The person can disconnect any app in **Account → AI apps**, which revokes the grant and every token.
- `surface:mcp_auth` stops new sign-ins.