# auth.md - Authenticating with Kamai

Kamai's MCP server is the one programmatic surface that requires auth. It is
protected by OAuth 2.0 with dynamic client registration (RFC 7591) and PKCE, so
agents register and obtain tokens without a human pre-provisioning credentials.

The REST API at https://api.kamai.io uses static API-key bearer tokens issued
from the Kamai Console (https://admin.kamai.io); it does not use the OAuth flow
described here.

## MCP endpoint

- Protected resource: https://mcp.kamai.io/mcp
- Transport: streamable HTTP
- Resource metadata: https://mcp.kamai.io/.well-known/oauth-protected-resource/mcp

A request without a valid token returns 401 with a `WWW-Authenticate: Bearer`
header whose `resource_metadata` points at the resource metadata above.

## Authorization server

Discovery (RFC 8414): https://auth.kamai.io/.well-known/oauth-authorization-server

- issuer: https://auth.kamai.io
- authorization_endpoint: https://auth.kamai.io/authorize
- token_endpoint: https://auth.kamai.io/token
- registration_endpoint: https://auth.kamai.io/register
- jwks_uri: https://auth.kamai.io/jwks.json
- grant_types_supported: authorization_code, refresh_token
- code_challenge_methods_supported: S256
- token_endpoint_auth_methods_supported: none (public clients)
- scopes_supported: mcp

This is pure OAuth 2.0, not OpenID Connect. There is no
`/.well-known/openid-configuration`; use the
`oauth-authorization-server` document above.

## How an agent connects

1. Discover the resource metadata, then the authorization server metadata above.
2. Register dynamically: `POST https://auth.kamai.io/register` with your `redirect_uris`,
   `grant_types: ["authorization_code", "refresh_token"]`, and
   `token_endpoint_auth_method: "none"`. You receive a `client_id`.
3. Run the authorization-code flow with PKCE (S256) and `scope=mcp`. The user
   signs in to their Kamai account and authorizes your client.
4. Exchange the code at `https://auth.kamai.io/token` for a Bearer access token.
5. Call https://mcp.kamai.io/mcp with `Authorization: Bearer <token>`.

Most MCP clients (Claude Desktop, Claude Code, Cursor) do all of this for you -
point the client at https://mcp.kamai.io/mcp and complete the browser sign-in on first
connect. See https://kamai.io/developers/mcp for client configuration.

## Agent registration

- Audience: AI agents and MCP clients that need to call https://mcp.kamai.io/mcp.
- Registration endpoint (register_uri): https://auth.kamai.io/register (RFC 7591 dynamic
  client registration, open - no pre-shared secret).
- Supported registration method: dynamic client registration for public
  clients (`token_endpoint_auth_method: "none"`), then authorization-code +
  PKCE (S256), scope `mcp`.
- Credential usage: the issued access token is a Bearer token sent in the
  `Authorization` header. Refresh tokens are supported via the
  `refresh_token` grant. Tokens are minted and revoked by the authorization
  server at https://auth.kamai.io.
