# auth.md: authenticating with SuppCo

How AI agents get access to SuppCo. Questions: support@supp.co.

## No sign-in needed

- **Public API**: `https://api.supp.co` serves the read-only catalog and research API without credentials. Spec: https://api.supp.co/openapi.json
- **Pages as Markdown**: request any `https://supp.co` page with `Accept: text/markdown`.
- **Public MCP tools**: product, brand and nutrient research on the MCP server below.

## Signing in (OAuth 2.1 + PKCE)

Stack tools and other account actions on the MCP server need an OAuth access token for the user.

- MCP endpoint: `https://api.supp.co/mcp` (Streamable HTTP).
- Protected resource metadata (RFC 9728): https://api.supp.co/.well-known/oauth-protected-resource (https://supp.co/.well-known/oauth-protected-resource describes this site, with the same authorization server and scopes)
- Authorization server: issuer `https://login.supp.co`, metadata (RFC 8414) at https://api.supp.co/.well-known/oauth-authorization-server
- Flow: authorization code with PKCE (`S256`). Register a client with Dynamic Client Registration (RFC 7591) at `https://login.supp.co/oauth/register`, send the user to `https://login.supp.co/oauth/authorize`, then exchange the code at `https://login.supp.co/oauth/token`. Request the `mcp` scope (add `offline_access` for a refresh token).
- Send the token as `Authorization: Bearer <token>`.

## Step 1 — Discover

A signed-out request answers 401 with a `WWW-Authenticate` header naming the protected resource metadata (RFC 9728) of what you called. The REST API, for example `GET https://api.supp.co/api`:

```http
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://api.supp.co/.well-known/oauth-protected-resource/api"
```

An account tool call on the MCP server `https://api.supp.co/mcp` names `https://api.supp.co/.well-known/oauth-protected-resource` instead.

1. Fetch that `resource_metadata` URL. Its `resource` is the API you called, `scopes_supported` lists the scopes it takes (`api` for REST, MCP scopes for `/mcp`), and `authorization_servers` is `["https://login.supp.co"]`.
2. Fetch `https://login.supp.co/.well-known/oauth-authorization-server` (RFC 8414; the same document is also served at `https://api.supp.co/.well-known/oauth-authorization-server`). Besides the standard OAuth endpoints, read its `agent_auth` object: `skill`, `identity_endpoint`, `claim_endpoint` and `identity_types_supported`. If `agent_auth` is missing, agent registration is off: use the sign-in flow above.

## Step 2 — Pick a method

`agent_auth.identity_types_supported` is `["anonymous"]`, so register as `anonymous` whatever else you hold. SuppCo trusts no ID-JAG issuer: `{"type":"identity_assertion"}` (id-jag) answers 400 `issuer_not_enabled`, and `{"type":"service_auth"}` answers 400 `service_auth_not_enabled`. To act on a user's account, register anonymously and have the user claim you (Step 4), or use the sign-in flow above.

## Step 3 — Register

Items 1–7 below run through Steps 3 and 4. Inside them, "step N" means item N of this list, not a `## Step` heading.

An agent can also register itself with no user, use the public MCP tools at once, and later ask a SuppCo user to claim it for access to their account. Requests to `/agent/identity*` take a JSON body; their errors are `application/problem+json` with an `error` code. `/oauth/token` takes a form body and answers errors as `{"error", "error_description"}`.

1. **Discover.** GET https://api.supp.co/.well-known/oauth-authorization-server and read its `agent_auth` object: `identity_endpoint` (`https://login.supp.co/agent/identity`), `claim_endpoint` (`https://login.supp.co/agent/identity/claim`), `identity_types_supported` (`["anonymous"]`) and `skill` (this page). If `agent_auth` is missing, registration is switched off (`/agent/identity` answers 404 `not_found`): use the sign-in flow above.
2. **Register.** `POST https://login.supp.co/agent/identity` with `{"type":"anonymous"}`. The response has:
   - `registration_id` (`reg_…`).
   - `identity_assertion`: a signed JWT you exchange for access tokens in step 3, valid until `assertion_expires`.
   - `pre_claim_scopes`: `["mcp:read"]`.
   - `claim_token` (`clm_…`): returned only in this response, so store it. The user must approve a claim before `claim_token_expires` (24 hours); once they approve, you can redeem it for 24 hours after the approval.
   - `claim_url` (the claim endpoint) and `post_claim_scopes` (`["mcp:read", "mcp:write"]`, what a user can grant).
3. **Get a pre-claim token.** `POST https://login.supp.co/oauth/token` with `grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=<identity_assertion>`. It returns `access_token`, `token_type` (`Bearer`), `expires_in` (3600) and `scope` (`mcp:read`). The token has no user, so it reaches only the public MCP tools; account tools answer 401. There is no refresh token: repeat this exchange when the token expires.

## Step 4 — Claim ceremony

Optional: only when the user wants you to act on their SuppCo account. Items 4–7 continue the list from Step 3.

4. **Start a claim** when the user wants you to act on their account. Ask for the email of their SuppCo account, then `POST https://login.supp.co/agent/identity/claim` with `{"claim_token": "clm_…", "email": "<their email>"}`. The response's `claim_attempt` holds `user_code` (6 digits), `verification_uri`, `expires_in` (600) and `interval` (5, in seconds). Calling it again starts a new attempt and voids the previous code. Errors: 401 `invalid_claim_token`; 410 `claim_expired` (register again); 409 `claimed_or_in_flight` (already claimed: go to step 6).
5. **Hand off to the user.** Tell them to open `verification_uri`, sign in to SuppCo with that email if asked, enter `user_code`, and choose the permissions to grant. The code expires in 10 minutes and locks after 5 wrong tries.
6. **Poll.** Every `interval` seconds, `POST https://login.supp.co/oauth/token` with `grant_type=urn:workos:agent-auth:grant-type:claim&claim_token=<claim_token>`. Until the user finishes, it answers 400 with one of:
   - `authorization_pending`: wait `interval` seconds and poll again.
   - `slow_down`: you polled sooner than `interval`; wait longer. HTTP 429 with `Retry-After` means more than 60 token requests a minute from your IP.
   - `expired_token`: the code expired (start a new claim, step 4) or the registration did (register again, step 2).
   - `invalid_grant`: unknown or revoked `claim_token`, or more than 24 hours since the user approved.
7. **Use the user's token.** Success returns `access_token` for the user, with `scope` set to what they granted (`mcp:read`, `mcp:write` or both) and `expires_in` 3600, plus a new `identity_assertion` valid for 30 days. Your pre-claim assertion and tokens stop working. When the token expires, exchange the new assertion as in step 3 for another user token. If the user revokes your access, exchanges answer `invalid_grant`.

Per IP, `POST /agent/identity` allows 10 requests an hour and `POST /agent/identity/claim` 20 an hour; past that it answers 429 with `Retry-After`.

## Step 5 — Exchange the assertion

`POST https://login.supp.co/oauth/token` (form body) with `grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=<identity_assertion>`, using the newest assertion you hold: the one from Step 3, or the one the claim returned in Step 4. The same assertion mints new access tokens until it expires. `invalid_grant` means it expired, was revoked, or was superseded by a claim: register again (Step 3).

## Step 6 — Use the access_token

Agent tokens carry MCP scopes, so use them on the MCP server, `https://api.supp.co/mcp` (Streamable HTTP, JSON-RPC 2.0), with `Authorization: Bearer <access_token>`:

1. `POST` an `initialize` request. Send the `Mcp-Session-Id` response header back on later requests.
2. `tools/list` returns every tool with its input schema.
3. `tools/call`, for example `{"name": "suppco_get_nutrient_info", "arguments": {"nutrient_name": "Magnesium"}}` (public) or `{"name": "suppco_get_my_stack", "arguments": {}}` (needs a claimed token with `mcp:read`).

An account tool called without a user token answers 401 with the `WWW-Authenticate` header from Step 1; a tool that needs a scope the token lacks (such as `mcp:write`) answers 403 with `error="insufficient_scope"`. The REST endpoints under `https://api.supp.co/api` that need sign-in take user tokens with the `api` scope, not agent tokens. When the access token expires, repeat Step 5; there is no refresh token.

## Errors

`/agent/identity*` errors are `application/problem+json` with an `error` code; `/oauth/token` errors are `{"error", "error_description"}`.

| Code                                                   | Where                                      | What to do                                                                                 |
| ------------------------------------------------------ | ------------------------------------------ | ------------------------------------------------------------------------------------------ |
| `invalid_request` (400)                                | `/agent/identity`, `/agent/identity/claim` | Fix the body: `type` must be `anonymous`; a claim needs `claim_token` and a valid `email`. |
| `issuer_not_enabled`, `service_auth_not_enabled` (400) | `/agent/identity`                          | Register as `anonymous` (Step 2).                                                          |
| `not_found` (404)                                      | `/agent/identity*`                         | Agent registration is off. Use the sign-in flow.                                           |
| `invalid_claim_token` (401)                            | `/agent/identity/claim`                    | Unknown or revoked `claim_token`. Register again (Step 3).                                 |
| `claimed_or_in_flight` (409)                           | `/agent/identity/claim`                    | Already claimed. Poll the token endpoint (Step 4, item 6).                                 |
| `claim_expired` (410)                                  | `/agent/identity/claim`                    | Registration expired. Register again (Step 3).                                             |
| `authorization_pending` (400)                          | `/oauth/token` (claim grant)               | The user hasn't finished. Poll again after `interval`.                                     |
| `slow_down` (400, or 429)                              | `/oauth/token`                             | Poll less often; on 429 wait for `Retry-After`.                                            |
| `expired_token` (400)                                  | `/oauth/token` (claim grant)               | Start a new claim (Step 4); if that answers `claim_expired`, register again.               |
| `invalid_grant` (400)                                  | `/oauth/token`                             | Assertion or `claim_token` expired, revoked or superseded. Register again (Step 3).        |
| 429 with `Retry-After`                                 | `/agent/identity`, `/agent/identity/claim` | Rate limited. Wait, then retry.                                                            |

Retry 5xx with backoff. Don't resend a 4xx unchanged; act on the table.

## Revocation

- **The user revokes you.** A user sees and revokes the agents they claimed at `https://login.supp.co/agent/identities`. That revokes your assertion and every token minted from it: your next request answers 401 and your next exchange `invalid_grant`. Register again (Step 3) and ask for a new claim.
- **Tokens expire.** Access tokens last 3600 seconds; get another with Step 5. You hold no client secret, so `https://login.supp.co/oauth/revoke` (RFC 7009) won't revoke agent tokens for you; drop a token you no longer need.
- SuppCo accepts no identity-provider events, so `agent_auth` has no `events_endpoint`.

## More

- Developer guide: https://supp.co/developers
- MCP Server Card: https://supp.co/.well-known/mcp/server-card.json
- Agent skill: https://supp.co/.well-known/agent-skills/suppco/SKILL.md
