# auth.md

You are an agent that wants to call Caruana Utilities. The resource server and the authorization server are both `util.caruana.me`. Listing tools (MCP `tools/list`, the A2A agent card, OpenAPI) needs no credentials; calling a tool does. Follow these steps in order.

## 1. Discover

A tool call without credentials answers 401 with:

```
WWW-Authenticate: Basic realm="Caruana Utilities", Bearer realm="Caruana Utilities", resource_metadata="https://util.caruana.me/.well-known/oauth-protected-resource"
```

Fetch the protected resource metadata (RFC 9728) from `resource_metadata`, or from https://util.caruana.me/.well-known/oauth-protected-resource directly. Its `authorization_servers` lists https://util.caruana.me; fetch that server's metadata (RFC 8414) at https://util.caruana.me/.well-known/oauth-authorization-server. The fields you need:

- `registration_endpoint`: where to get a client ID and secret (step 3).
- `token_endpoint`: where to exchange them for a bearer token (step 4, optional).
- `grant_types_supported`: `client_credentials` only. There are no users, scopes or consent screens.
- `agent_auth.identity_endpoint`: the same registration endpoint; `agent_auth.identity_types_supported` is `["anonymous"]`.

## 2. Pick a method

Registration here is **anonymous**: no user identity is asserted and no claim ceremony is needed, so there is no consent step.

- You can keep a client ID and secret: register once (step 3) and send them with HTTP Basic on every call. Simplest.
- Your client prefers short-lived bearer tokens: register once, then exchange the credentials for a token (step 4).
- A person is setting this up by hand: they use https://util.caruana.me/credentials/ instead.

There is no sign-in with another identity provider, and none is needed.

## 3. Register

### anonymous

One call, no account and no email confirmation (RFC 7591 dynamic client registration with an `agent` profile):

```http
POST https://util.caruana.me/api/auth/register
Content-Type: application/json

{"client_name": "Release checker", "agent": {"purpose": "Verify release checksums before deploys"}}
```

```json
{"client_id": "cu_id_...", "client_secret": "cu_sk_...", "grant_types": ["client_credentials"], "token_endpoint_auth_method": "client_secret_basic", "expires_at": "...", "renewable_until": "..."}
```

The secret is shown once. Tell us as much as you can about who you work for: the registration schema is in the [agent card](https://util.caruana.me/.well-known/agent-card.json) extension, or send the A2A skill `register` to https://util.caruana.me/a2a.

## 4. Exchange for a token (optional)

```http
POST https://util.caruana.me/api/auth/token
Authorization: Basic base64(client_id:client_secret)
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials
```

```json
{"access_token": "...", "token_type": "Bearer", "expires_in": 3600}
```

## 5. Use the credentials

Send either `Authorization: Basic base64(client_id:client_secret)` or `Authorization: Bearer <access_token>`. The same credentials work for the HTTP API (https://util.caruana.me/api/), the MCP server (https://util.caruana.me/mcp) and A2A (https://util.caruana.me/a2a).

- Tokens last 1 hour; get a new one from step 4 when one expires.
- Credentials last 30 days. Renew them any time, even up to 90 days after expiry, with `POST https://util.caruana.me/api/auth/renew` and the same Basic credentials.
- 60 calls per minute per client.

## 6. Errors

| Code | Where | What to do |
|---|---|---|
| `unauthenticated` (401) | any tool call | Send credentials (step 5), or register (step 3). |
| `credentials_expired` (401) | any tool call | Renew with `POST https://util.caruana.me/api/auth/renew`; after the grace period, register again. |
| `revoked` (403; `invalid_client` 401 at the token endpoint) | any tool call, token, renew | The owner revoked these credentials. Register again only if you were not revoked for abuse. |
| `invalid_client` (401) | token endpoint | Wrong ID or secret. |
| `unsupported_grant_type` (400) | token endpoint | Use `grant_type=client_credentials`. |
| `invalid_client_metadata` (400) | registration | Fix the fields named in `error_description`. |
| `rate_limited` (429) | any tool call | Wait for `Retry-After`. |

## 7. Revocation

- Tokens: they expire after 1 hour; stop using one and it is gone.
- Credentials: the service owner can revoke any client. A revoked client fails every call and cannot renew or get tokens. Expired credentials stop working too, and can be renewed only within the grace period.

## Privacy

Inputs and results are never stored or logged; one metadata row per call is (operation, time, status, duration, sizes, country). Details: https://util.caruana.me/security/
