# auth.md

Not an agent? Landbot's human-facing site is https://landbot.io and the app is https://app.landbot.io.

You are an agent. This document tells you how to register a client and obtain a credential for the
Landbot agent surface — the MCP server at `https://mcp.landbot.io/mcp`. The marketing site at
`https://landbot.io` requires no authentication; only the MCP server does.

The authorization server is `https://app.landbot.io` and the only flow is OAuth 2.1 authorization
code with PKCE (S256, mandatory). Access and refresh tokens are opaque bearer tokens — do not try
to parse or verify them locally (there is no `jwks_uri`). A Landbot user must approve your
authorization request; there is no fully unattended token issuance.

## Step 1 — Discover

- Authorization Server Metadata (RFC 8414): `GET https://app.landbot.io/.well-known/oauth-authorization-server`
- Protected Resource Metadata (RFC 9728): `GET https://mcp.landbot.io/.well-known/oauth-protected-resource`
  (the copy at `https://landbot.io/.well-known/oauth-protected-resource` redirects there)

The available scopes are the `scopes_supported` arrays in those two documents — request only the
ones you need.

## Step 2 — Register your client (CIMD: anonymous, no registration endpoint)

There is no Dynamic Client Registration endpoint. Client registration is anonymous and automatic
via Client ID Metadata Documents (`client_id_metadata_document_supported: true` in the AS
metadata): publish a client metadata document at an HTTPS URL you control and use that URL as your
`client_id`. The authorization server fetches it when you start the flow.

```json
{
  "client_id": "https://agent.example.com/.well-known/client-metadata.json",
  "client_name": "Example Agent",
  "redirect_uris": ["https://agent.example.com/callback"],
  "grant_types": ["authorization_code", "refresh_token"],
  "response_types": ["code"],
  "token_endpoint_auth_method": "none"
}
```

Host this JSON at the `client_id` URL itself.

## Step 3 — Authorize (user consent required)

Send the user to the authorization endpoint:

```
GET https://app.landbot.io/o/authorize/
    ?response_type=code
    &client_id=<your client metadata URL, URL-encoded>
    &redirect_uri=<one of your redirect_uris>
    &scope=<space-separated scopes from scopes_supported, URL-encoded>
    &state=<random>
    &code_challenge=<S256 code challenge>
    &code_challenge_method=S256
```

The user signs in to Landbot and approves the requested scopes; the authorization code returns to
your `redirect_uri`.

## Step 4 — Exchange the code for a credential

```http
POST /o/token/ HTTP/1.1
Host: app.landbot.io
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=<code>&redirect_uri=<redirect_uri>&client_id=<your client metadata URL>&code_verifier=<PKCE verifier>
```

Response (200):

```json
{
  "access_token": "<opaque token>",
  "token_type": "Bearer",
  "refresh_token": "<opaque token>",
  "scope": "<granted scopes>"
}
```

Store the refresh token securely. When the access token expires (401 `invalid_token`), send
`grant_type=refresh_token` to the same token endpoint.

## Step 5 — Use the credential

Call the MCP server with the access token in the `Authorization` header:

```http
POST /mcp HTTP/1.1
Host: mcp.landbot.io
Authorization: Bearer <access_token>
```

## Revocation

```http
POST /o/revoke_token/ HTTP/1.1
Host: app.landbot.io
Content-Type: application/x-www-form-urlencoded

token=<access or refresh token>&client_id=<your client metadata URL>
```

## Errors

- 400 `invalid_grant` at `/o/token/` — code expired, already used, or PKCE verifier wrong. Restart at Step 3.
- 401 `invalid_token` at the MCP server — access token expired or revoked. Refresh, or restart at Step 3.
- 403 `insufficient_scope` at the MCP server — the token lacks a scope the call needs. The `WWW-Authenticate` challenge's `scope` lists every scope the server supports: re-authorize asking for all of them (a token that only grants the missing one loses the others).
- 429 / 5xx — back off exponentially and retry.
