---
title: "OAuth"
description: "Authorization, token exchange and discovery for scoped third-party apps."
url: https://doorman.fyi/docs/reference/oauth
markdown: https://doorman.fyi/docs/reference/oauth.md
area: "API reference"
section: "API reference"
---

# OAuth

Authorization, token exchange and discovery for scoped third-party apps.

Source: https://doorman.fyi/docs/reference/oauth

## Discover authorization

`GET /.well-known/oauth-authorization-server`

Access `public`: no credential.

Issuer metadata for authorization-code PKCE, rotating refresh tokens, Client ID Metadata Documents and dynamic client registration.

Public OAuth protocol operation: omit API bearer credentials and cookies. Approval still requires explicit browser consent.

Also available as [`client.oauth.metadata`](https://doorman.fyi/docs/python/reference/oauth.md#oauth-metadata) in Python.

Answers `200`: Authorization-server metadata.

**Response 200: OAuthServerMetadata**
OAuth authorization-server discovery.
- `issuer` (string)
- `authorization_endpoint` (string)
- `token_endpoint` (string)
- `registration_endpoint` (string)
- `response_types_supported` ("code"[])
- `grant_types_supported` (("authorization_code" | "refresh_token")[])
- `code_challenge_methods_supported` ("S256"[])
- `token_endpoint_auth_methods_supported` (("none" | "client_secret_post")[])
- `scopes_supported` (("account:read" | "inboxes:read" | "inboxes:write" | "mail:read" | "mail:write" | "mail:send" | "mail:draft" | "events:read" | "webhooks:manage" | "rules:manage" | "keys:manage" | "offline_access")[])
- `authorization_response_iss_parameter_supported` (true)
- `client_id_metadata_document_supported` (true)

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s "https://api.doorman.fyi/.well-known/oauth-authorization-server"
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/.well-known/oauth-authorization-server", {
  headers: {
  },
  redirect: "manual", credentials: "omit",
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const result = await response.json();
```

Python:
```python
import requests

response = requests.get(
    "https://api.doorman.fyi/.well-known/oauth-authorization-server",
    headers={},
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Discover the API resource

`GET /.well-known/oauth-protected-resource`

Access `public`: no credential.

The Inbox REST API resource identifier, authorization server and supported scopes.

Public OAuth protocol operation: omit API bearer credentials and cookies. Approval still requires explicit browser consent.

Also available as [`client.oauth.resource`](https://doorman.fyi/docs/python/reference/oauth.md#oauth-resource) in Python.

Answers `200`: Protected-resource metadata.

**Response 200: OAuthResourceMetadata**
Protected-resource discovery for the Inbox API or its MCP endpoint.
- `resource` (string)
- `authorization_servers` (string[])
- `scopes_supported` (("account:read" | "inboxes:read" | "inboxes:write" | "mail:read" | "mail:write" | "mail:send" | "mail:draft" | "events:read" | "webhooks:manage" | "rules:manage")[])
- `bearer_methods_supported` ("header"[])

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s "https://api.doorman.fyi/.well-known/oauth-protected-resource"
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/.well-known/oauth-protected-resource", {
  headers: {
  },
  redirect: "manual", credentials: "omit",
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const result = await response.json();
```

Python:
```python
import requests

response = requests.get(
    "https://api.doorman.fyi/.well-known/oauth-protected-resource",
    headers={},
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Discover the MCP resource

`GET /.well-known/oauth-protected-resource/mcp`

Access `public`: no credential.

The MCP resource identifier, authorization server and the permissions an agent needs by default; the other app permissions remain requestable. MCP tokens cannot be used directly at REST endpoints.

Public OAuth protocol operation: omit API bearer credentials and cookies. Approval still requires explicit browser consent.

Also available as [`client.oauth.mcp_resource`](https://doorman.fyi/docs/python/reference/oauth.md#oauth-mcpResource) in Python.

Answers `200`: MCP protected-resource metadata.

**Response 200: OAuthResourceMetadata**
Protected-resource discovery for the Inbox API or its MCP endpoint.
- `resource` (string)
- `authorization_servers` (string[])
- `scopes_supported` (("account:read" | "inboxes:read" | "inboxes:write" | "mail:read" | "mail:write" | "mail:send" | "mail:draft" | "events:read" | "webhooks:manage" | "rules:manage")[])
- `bearer_methods_supported` ("header"[])

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s "https://api.doorman.fyi/.well-known/oauth-protected-resource/mcp"
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/.well-known/oauth-protected-resource/mcp", {
  headers: {
  },
  redirect: "manual", credentials: "omit",
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const result = await response.json();
```

Python:
```python
import requests

response = requests.get(
    "https://api.doorman.fyi/.well-known/oauth-protected-resource/mcp",
    headers={},
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Begin app authorization

`GET /oauth/authorize`

Access `public`: no credential.

Validate a client, its redirect, the resource, the requested scopes and the S256 challenge before redirecting to console consent. A client named by a metadata document URL has that document read and checked first. Unrecognized parameters are ignored. Invalid requests never redirect.

Public OAuth protocol operation: omit API bearer credentials and cookies. Approval still requires explicit browser consent.

Also available as [`client.oauth.authorize`](https://doorman.fyi/docs/python/reference/oauth.md#oauth-authorize) in Python.

**Parameters**

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `response_type` | query | `"code"` | yes | Always `code`. |
| `client_id` | query | `string \| string` | yes | The client: an id this API issued, or the URL of the client's Client ID Metadata Document. Example: `app_01jc5f1a2b3c4d5e6f7g8h9j0k`. |
| `redirect_uri` | query | `string` | yes | A redirect the client registered. A loopback redirect matches on any port; every other redirect matches exactly. |
| `resource` | query | `string` | yes | The API origin for REST access, or the API origin followed by `/mcp` for the MCP endpoint. |
| `scope` | query | `string` | no | Space-separated permissions. When omitted, the request is for the default agent permissions the client may hold. |
| `state` | query | `string` | no | An opaque value returned unchanged with the answer. A client that sends none gets none back. |
| `code_challenge` | query | `string` | yes | The S256 PKCE challenge of the verifier the client keeps. |
| `code_challenge_method` | query | `"S256"` | yes | Always `S256`. |

Answers `303`: Continue to console consent.

Response header `Location`: The console consent page.

Answers `400`: The OAuth request was refused.

**Response 400: OAuthError**
An OAuth protocol error, distinct from the Inbox API error envelope.
- `error` ("invalid_request" | "invalid_client" | "invalid_grant" | "invalid_scope" | "unsupported_grant_type" | "temporarily_unavailable" | "invalid_redirect_uri" | "invalid_client_metadata")
- `error_description` (string, optional)

Answers `401`: Client authentication failed.

**Response 401: OAuthError**
An OAuth protocol error, distinct from the Inbox API error envelope.
- `error` ("invalid_request" | "invalid_client" | "invalid_grant" | "invalid_scope" | "unsupported_grant_type" | "temporarily_unavailable" | "invalid_redirect_uri" | "invalid_client_metadata")
- `error_description` (string, optional)

Answers `429`: The request or allocation limit was reached.

**Response 429: OAuthError**
An OAuth protocol error, distinct from the Inbox API error envelope.
- `error` ("invalid_request" | "invalid_client" | "invalid_grant" | "invalid_scope" | "unsupported_grant_type" | "temporarily_unavailable" | "invalid_redirect_uri" | "invalid_client_metadata")
- `error_description` (string, optional)

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 500 | `internal_error` | Something went wrong on the server. |

Build the authorization URL with a fresh S256 challenge and saved state, then navigate in the user's browser. Do not fetch this route with an API credential or automatically approve the redirect. See the [TypeScript flow](https://doorman.fyi/docs/oauth.md#authorize) and [Python flow](https://doorman.fyi/docs/python.md#oauth).

## Exchange or refresh tokens

`POST /oauth/token`

Access `public`: no credential.

Form-encoded code exchange with PKCE or single-use refresh rotation. Reuse of a consumed credential revokes its token family. A connection stays alive while it is refreshed, up to an absolute limit.

Public OAuth protocol operation: omit API bearer credentials and cookies. Approval still requires explicit browser consent.

Also available as [`client.oauth.token`](https://doorman.fyi/docs/python/reference/oauth.md#oauth-token) in Python.

**Request body (application/x-www-form-urlencoded): OAuthTokenRequest**
A form-encoded code exchange or refresh. Resource and client are bound to the original grant. Other fields are ignored.
- `grant_type` ("authorization_code" | "refresh_token")
- `client_id` (string | string): A client id this API issued, or the URL of the client's Client ID Metadata Document. Example: `app_01jc5f1a2b3c4d5e6f7g8h9j0k`
- `client_secret` (string, optional)
- `resource` (string)
- `code` (string, optional)
- `redirect_uri` (string, optional)
- `code_verifier` (string, optional)
- `refresh_token` (string, optional)
- `scope` (string, optional)

Answers `200`: The bearer and rotating refresh tokens.

**Response 200: OAuthTokens**
Short-lived bearer access and a rotating refresh token. Store them as secrets.
- `access_token` (string)
- `token_type` ("Bearer")
- `expires_in` (integer)
- `refresh_token` (string)
- `scope` (string)

Answers `400`: The OAuth request was refused.

**Response 400: OAuthError**
An OAuth protocol error, distinct from the Inbox API error envelope.
- `error` ("invalid_request" | "invalid_client" | "invalid_grant" | "invalid_scope" | "unsupported_grant_type" | "temporarily_unavailable" | "invalid_redirect_uri" | "invalid_client_metadata")
- `error_description` (string, optional)

Answers `401`: Client authentication failed.

**Response 401: OAuthError**
An OAuth protocol error, distinct from the Inbox API error envelope.
- `error` ("invalid_request" | "invalid_client" | "invalid_grant" | "invalid_scope" | "unsupported_grant_type" | "temporarily_unavailable" | "invalid_redirect_uri" | "invalid_client_metadata")
- `error_description` (string, optional)

Answers `429`: The request or allocation limit was reached.

**Response 429: OAuthError**
An OAuth protocol error, distinct from the Inbox API error envelope.
- `error` ("invalid_request" | "invalid_client" | "invalid_grant" | "invalid_scope" | "unsupported_grant_type" | "temporarily_unavailable" | "invalid_redirect_uri" | "invalid_client_metadata")
- `error_description` (string, optional)

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s -X POST "https://api.doorman.fyi/oauth/token" \
  --data-urlencode 'grant_type=authorization_code' \
  --data-urlencode 'client_id=app_01jc5f1a2b3c4d5e6f7g8h9j0k' \
  --data-urlencode 'resource=https://api.doorman.example' \
  --data-urlencode 'code=replace-with-the-validated-callback-code' \
  --data-urlencode 'redirect_uri=https://agent.example.com/callback' \
  --data-urlencode 'code_verifier=replace-with-the-verifier-saved-before-the-redirect'
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/oauth/token", {
  method: "POST",
  headers: {
    "content-type": "application/x-www-form-urlencoded",
  },
  redirect: "manual", credentials: "omit",
  body: new URLSearchParams({
    "grant_type": "authorization_code",
    "client_id": "app_01jc5f1a2b3c4d5e6f7g8h9j0k",
    "resource": "https://api.doorman.example",
    "code": "replace-with-the-validated-callback-code",
    "redirect_uri": "https://agent.example.com/callback",
    "code_verifier": "replace-with-the-verifier-saved-before-the-redirect"
  }),
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const result = await response.json();
```

Python:
```python
import requests

response = requests.post(
    "https://api.doorman.fyi/oauth/token",
    headers={},
    data={
        "grant_type": "authorization_code",
        "client_id": "app_01jc5f1a2b3c4d5e6f7g8h9j0k",
        "resource": "https://api.doorman.example",
        "code": "replace-with-the-validated-callback-code",
        "redirect_uri": "https://agent.example.com/callback",
        "code_verifier": "replace-with-the-verifier-saved-before-the-redirect",
    },
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Register a public client dynamically

`POST /oauth/register`

Access `public`: no credential.

Create an unverified public client with bounded lifetime and quotas. Metadata this API does not use is ignored and the answer states what was registered. Registration alone grants no account access.

Public OAuth protocol operation: omit API bearer credentials and cookies. Approval still requires explicit browser consent.

Also available as [`client.oauth.register`](https://doorman.fyi/docs/python/reference/oauth.md#oauth-register) in Python.

**Request body (application/json): RegisterOAuthClient**
Dynamic registration of a public client, not a verified developer identity. Other client metadata is ignored and redirects the API cannot use are dropped. The answer states what was registered: always a public client with both grants.
- `client_name` (string, optional)
- `redirect_uris` (string[])
- `token_endpoint_auth_method` (string, optional)
- `grant_types` (string[], optional)
- `response_types` (string[], optional)
- `scope` (string, optional)

Answers `201`: The public client.

**Response 201: RegisteredOAuthClient**
A bounded public client registration. No client secret or registration management token is issued.
- `client_id` (string): An OAuth client identifier. Example: `app_01jc5f1a2b3c4d5e6f7g8h9j0k`
- `client_name` (string)
- `redirect_uris` (string[])
- `token_endpoint_auth_method` ("none")
- `grant_types` (("authorization_code" | "refresh_token")[])
- `response_types` ("code"[])
- `scope` (string)
- `client_id_issued_at` (integer)
- `client_id_expires_at` (integer)

Answers `400`: The OAuth request was refused.

**Response 400: OAuthError**
An OAuth protocol error, distinct from the Inbox API error envelope.
- `error` ("invalid_request" | "invalid_client" | "invalid_grant" | "invalid_scope" | "unsupported_grant_type" | "temporarily_unavailable" | "invalid_redirect_uri" | "invalid_client_metadata")
- `error_description` (string, optional)

Answers `401`: Client authentication failed.

**Response 401: OAuthError**
An OAuth protocol error, distinct from the Inbox API error envelope.
- `error` ("invalid_request" | "invalid_client" | "invalid_grant" | "invalid_scope" | "unsupported_grant_type" | "temporarily_unavailable" | "invalid_redirect_uri" | "invalid_client_metadata")
- `error_description` (string, optional)

Answers `429`: The request or allocation limit was reached.

**Response 429: OAuthError**
An OAuth protocol error, distinct from the Inbox API error envelope.
- `error` ("invalid_request" | "invalid_client" | "invalid_grant" | "invalid_scope" | "unsupported_grant_type" | "temporarily_unavailable" | "invalid_redirect_uri" | "invalid_client_metadata")
- `error_description` (string, optional)

**Errors**

| Status | Error | Meaning |
| --- | --- | --- |
| 500 | `internal_error` | Something went wrong on the server. |

curl:
```sh
curl -s -X POST "https://api.doorman.fyi/oauth/register" \
  -H "content-type: application/json" \
  -d '{
    "client_name": "Mail triage",
    "redirect_uris": [
      "https://agent.example.com/callback"
    ],
    "scope": "mail:read"
  }'
```

TypeScript:
```ts
const response = await fetch("https://api.doorman.fyi/oauth/register", {
  method: "POST",
  headers: {
    "content-type": "application/json",
  },
  redirect: "manual", credentials: "omit",
  body: JSON.stringify({
    "client_name": "Mail triage",
    "redirect_uris": [
      "https://agent.example.com/callback"
    ],
    "scope": "mail:read"
  }),
});
if (!response.ok) throw new Error(`The API answered ${response.status}.`);
const result = await response.json();
```

Python:
```python
import requests

response = requests.post(
    "https://api.doorman.fyi/oauth/register",
    headers={},
    json={
        "client_name": "Mail triage",
        "redirect_uris": ["https://agent.example.com/callback"],
        "scope": "mail:read",
    },
    allow_redirects=False, timeout=30,
)
response.raise_for_status()
result = response.json()
```
