---
title: "Apps and OAuth"
description: "Delegate account access through explicit consent, S256 PKCE, resource-bound tokens and revocable installations without sharing an API key."
url: https://doorman.fyi/docs/oauth
markdown: https://doorman.fyi/docs/oauth.md
area: "Guides"
section: "Access"
---

# Apps and OAuth

Delegate account access through explicit consent, S256 PKCE, resource-bound tokens and revocable installations without sharing an API key.

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

## Register an app

> Note: SDK registry publication is a separate release gate. Until it clears, build the SDK packages from the repository; see [Installing the packages](https://doorman.fyi/docs/sdk.md#install).

Use [OAuth clients in the console](https://doorman.fyi/console/apps), one of the developer tools, to register a client with exact redirect URIs and the permissions it may request. Registration is not an installation and grants no access to another account. Public clients use `none`; a server that can keep a secret may use `client_secret_post`. A client name is a label, not proof of a verified developer.

A developer can keep 25 active apps, with up to 10 redirects each. A redirect uses HTTPS, or HTTP on the client's own machine: `http://localhost`, `http://127.0.0.1` or `http://[::1]`. Nothing else over plain HTTP is a redirect, and private-use URI schemes are not accepted. Wildcards, fragments and embedded credentials are refused.

At the authorization endpoint a loopback redirect matches a registered one when the host, the path and the query are equal. The port may differ, because a native client listens on whichever port is free. The three loopback names are not interchangeable, and every other redirect matches exactly. The code remembers the redirect it was sent to, port included, and the token endpoint requires exactly that one.

The [app operations](https://doorman.fyi/docs/reference/apps.md#apps-create) and [installation management](https://doorman.fyi/docs/reference/apps.md#installs-list) require the person's console session. Neither API keys nor app access tokens can create apps, approve consent or revoke someone else's grants. Confidential client secrets appear only on creation or rotation; store them outside source code and logs.

In an [organization](https://doorman.fyi/docs/organizations.md#agents), the apps and the installations belong to the organization's account and every member can list them. Registering or changing an app takes the member's `apps:manage`; opening a consent request, deciding it and revoking an installation take `agents:connect`.

An agent host does not need this step: it registers itself or names itself by a document it publishes, as [the next section](https://doorman.fyi/docs/oauth.md#clients) describes. A person connects one with the steps in [Connect your agent](https://doorman.fyi/docs/connect.md).

## Clients that register or identify themselves

A client nobody registered in the console is known in one of two ways. Neither grants access by itself: the person still approves in the browser, and the approval screen shows what was and was not checked about the client.

### Dynamic registration

[`POST /oauth/register`](https://doorman.fyi/docs/reference/oauth.md#oauth-register) registers a public client without a credential. It reads `client_name`, `redirect_uris`, `grant_types`, `response_types`, `token_endpoint_auth_method` and `scope`, and ignores every other field a host sends. A field set to null counts as left out, and so does a blank `scope`: some serializers write a field they mean to leave out that way.

- It always registers a public client with both grants, `authorization_code` and `refresh_token`, whatever method was asked for. It issues neither a secret nor a registration-management credential.
- Of the redirects it keeps the ones it can use and drops the others. With none left it answers `invalid_redirect_uri`.
- Grants that leave out `authorization_code`, or response types that leave out `code`, answer `invalid_client_metadata`.
- A missing name becomes `Unnamed app`. A name is stored as one line of at most 100 characters, without control, invisible or direction-changing characters.
- A registration that names no `scope` may later ask for any permission an app can hold. What it gets is decided at approval.
- The answer states what was registered, not what was sent: the redirects that were kept, `token_endpoint_auth_method` as `none`, both grants, the scope and `client_id_expires_at`.

A self-registered client lapses 30 days after it was registered or last exchanged a token. Every exchange or refresh that succeeds moves that date forward, so a client in use stays registered. A lapsed client answers `401 invalid_client` at the token endpoint, which is what tells a host to register again.

Registration is anonymous and rate-limited, so the clients nobody has approved are bounded, at 2,000. A client stops counting once an account approves it. When the bound is reached, the oldest unapproved client that nobody is being asked about gives way to the new one; only when every such client has an approval waiting does registration answer `429`.

Nothing about a self-registered client is checked, its name included. The approval screen says so, and the consent request and the installation report it as `dynamic`.

### Client ID Metadata Documents

A client may instead send the URL of a Client ID Metadata Document as its `client_id`: a JSON document it publishes about itself. Discovery advertises this with `client_id_metadata_document_supported`. The URL is canonical `https` on a public DNS name and the default port, with a path and no credentials, query or fragment, and at most 512 characters. A URL that is not in that form is a malformed `client_id`, which answers `invalid_request`.

- A document cannot be served from the API's own host.
- The API fetches the document with one `GET` that follows no redirect and carries no credential, within 5 seconds and 8 KiB.
- The document must be a JSON object whose `client_id` is that URL, with at least one usable redirect in `redirect_uris`. The usable ones are kept, up to 20, and the others dropped.
- A `client_name` is optional. A client that gives no name goes by the host that serves its document.
- The client is always public. A document that carries a secret or asks for any client authentication is refused, since the API would not be checking what the client believes it is.
- Fields the API does not read are ignored and a field set to null counts as left out, as in a registration. `grant_types` and `response_types`, where the document states them, must include `authorization_code` and `code`.
- The identity is stored and read again after 24 hours. If that read fails, authorization fails: the stored copy is not trusted in its place.
- A failure at any of these answers `invalid_client_metadata`.
- A changed document updates the name and the redirects for future requests and leaves existing installations alone. A person approved them, and the host that published the document then is the host publishing it now.
- The token endpoint never fetches. It uses the stored identity, and grants are compared by the stored client, not by the string a client sent.
- Reading a document is work done for a stranger, so documents that are not stored yet have a rate limit of their own. Over it the request answers `429 temporarily_unavailable`.
- Stored identities nobody has approved are bounded as self-registered clients are, at 2,000, and the oldest gives way to a new one in the same way.

What was verified is the domain that serves the document, and that is what the person is shown. The name in the document is still only what that domain says about itself. The consent request and the installation carry the URL as `metadataUrl`.

At most 100 approvals may wait for one client at a time, and 10,000 for all clients together. One published identity stands for every person who uses that host, so only the second bound applies to it.

## Authorize with S256 PKCE

- Generate a new random verifier and state for each attempt. Keep both in the initiating user's server-side session; send only the S256 challenge in the authorization URL.
- Choose the exact registered redirect, explicit resource and least-privilege scope set. Open the URL in the user's browser; the console binds the request to that browser session and to the account the person is working in.
- The consent page shows the client, account, redirect, resource and permissions. A person with several accounts can change the account there before deciding: the request follows them within the same session, and the grant is for the account shown when they decide. Only an explicit Allow action grants access; Deny returns `access_denied`. The assistant cannot approve consent.
- At callback, validate the redirect origin, path and registered query, the saved state and the expected issuer before reading the code. Reject duplicate state, issuer, code or error parameters.
- Exchange the code once with the same client, redirect, resource and verifier. Confidential clients include `client_secret` in the form body, never in a URL.

TypeScript: start authorization:
```ts
import { InboxOAuth, createPkce } from "@doorman/inbox-sdk";

const oauth = new InboxOAuth({ baseUrl: "https://api.doorman.fyi" });
const pkce = await createPkce();
// Save pkce.verifier and pkce.state in the initiating user's session.
const authorizationUrl = oauth.authorizationUrl({
  response_type: "code",
  client_id: clientId,
  redirect_uri: "https://agent.example.com/callback",
  resource: "https://api.doorman.fyi",
  scope: "account:read inboxes:read mail:read",
  state: pkce.state, code_challenge: pkce.challenge,
  code_challenge_method: "S256",
});
// Navigate the browser to authorizationUrl; this does not approve access.
```

TypeScript: handle the callback:
```ts
import { parseOAuthCallback } from "@doorman/inbox-sdk";

// Load pkce from the same user's session, then consume it once.
const code = parseOAuthCallback(callbackUrl, {
  redirectUri: "https://agent.example.com/callback",
  issuer: "https://api.doorman.fyi", state: pkce.state,
});
const tokens = await oauth.token({
  grant_type: "authorization_code", client_id: clientId, code,
  redirect_uri: "https://agent.example.com/callback",
  resource: "https://api.doorman.fyi", code_verifier: pkce.verifier,
  // Confidential clients also supply client_secret from secure storage.
});
// Store tokens securely. Do not print them or put them in browser URLs.
```

The `scope` is optional. A request without one asks for [the default agent permissions](https://doorman.fyi/docs/oauth.md#scopes) the client may hold, and every other permission is asked for by name. `offline_access` is accepted wherever a scope is read and means nothing: every grant already carries a refresh token, so it is never stored or returned. Any other scope this API does not have is refused.

The authorization and token endpoints read the parameters they name, once each, and ignore every other one, as OAuth asks of a server. A parameter sent without a value counts as left out. A parameter that is read and sent twice is refused.

The consent request the console reads, an [`OAuthConsent`](https://doorman.fyi/docs/reference/schemas.md#OAuthConsent), carries what is known about the client: `client.dynamic`, true for a client that registered itself, and `client.metadataUrl`, the identity document of a client that published one.

Consent requests expire after 15 minutes, long enough to sign up on the way to the consent screen; authorization codes after 60 seconds. The SDK's public OAuth calls omit bearer credentials and cookies, refuse redirects and never retry automatically. Protocol failures are `OAuthProtocolError`, distinct from REST `ApiError`. See [Python OAuth helpers](https://doorman.fyi/docs/python.md#oauth) for the second-language flow.

[The app a person connects](https://doorman.fyi/docs/sample.md#connector) is a complete TypeScript app that follows these steps, with its source: the state cookie, the callback checks, token rotation and what it does when the access is taken back.

## Permissions and account boundaries

| Scope | Permission |
| --- | --- |
| `account:read` | Read account identity, plan, usage and aggregate activity. |
| `inboxes:read` | Read inbox addresses, metadata and activity summaries. |
| `inboxes:write` | Create, update and delete inboxes. |
| `mail:read` | Read messages, threads, attachments and mail-bearing events, and the services and verification codes found in mail. |
| `mail:write` | Change thread read state, metadata and labels, trash threads, record the services an address signs up for, and start a sign-in the owner allows. |
| `mail:send` | Send mail and replies from the account's inboxes. |
| `mail:draft` | Write drafts for the owner to send. It sends nothing. |
| `events:read` | Read and stream the event log, including message content. |
| `webhooks:manage` | Manage this installation's webhook endpoints and deliveries. |
| `rules:manage` | Manage this installation's durable inbound rules. |

The default agent permissions are `account:read`, `inboxes:read`, `mail:read`, `mail:write`, `mail:send`: what an agent needs to read, file and answer mail. A request without a `scope` asks for these, limited to what the client is registered for. Creating and deleting inboxes, webhooks, rules and the event log stay available to a client that asks for them by name.

Every [reference operation](https://doorman.fyi/docs/reference.md) lists all required scopes and whether it allows delegated access. Scopes limit actions across the consenting account; they are not an inbox allowlist. Existing account and inbox API keys retain their capabilities.

- Events and streams require both `events:read` and `mail:read`, because events can contain full message text.
- Webhook management requires `webhooks:manage`, `events:read` and `mail:read`. Apps manage installation-owned endpoints, not legacy inbox webhooks.
- Rules require `rules:manage`, `mail:read`, `mail:write` and `mail:send`, even for a label-only rule, because editing a rule can authorize future sends.
- Apps cannot obtain `keys:manage`, mint unrestricted keys, or provision an inline key or legacy webhook when creating an inbox.
- Apps cannot manage custom domains or create an inbox on one: no permission covers them. Inboxes that already live on a custom domain stay reachable through the inbox and mail permissions.
- Endpoints, rules, delivery histories and delivery-failure events are filtered to the calling installation. Revocation is checked again before background work runs.

## Refresh and revocation

Access tokens last up to 15 minutes. A connection, the chain of refresh tokens that follows one approval, ends 30 days after its last refresh or 365 days after it was approved, whichever comes first. A connection in use is never interrupted inside that year, and one that goes unused ends on its own. Near the end an access token answers for no longer than what is left of its connection. Pass the access token as the SDK's `apiKey` or `api_key` value. It is not a `dm_` API key.

Refresh with `grant_type=refresh_token`, the current refresh token, client ID and the original resource. A refresh can keep or narrow scopes, never widen them. Serialize refreshes per grant and atomically replace the stored token pair on success.

> Warning: Codes and refresh tokens are single-use. Reusing either revokes the family, including its access tokens. Do not automatically repeat an exchange after an ambiguous network failure; start a new authorization when the result cannot be recovered.

A used refresh token is remembered until it would have expired anyway. Presented after that, it is an expired token, not evidence of theft. A connection approved before these lifetimes were introduced keeps the 30 days from approval it was given; the new lifetimes apply from the next approval.

[`GET /v1/app-installs`](https://doorman.fyi/docs/reference/apps.md#installs-list) answers each grant as an [`AppInstall`](https://doorman.fyi/docs/reference/schemas.md#AppInstall) with what a person needs to see: `lastUsedAt`, when the client last used it, to the minute; `expiresAt`, when its connection ends unless the client uses it first, or null when no connection is alive; `dynamic`, true for a client that registered itself; and `metadataUrl`, the identity document of a client that published one.

Revoke an installation in the console: [Apps](https://doorman.fyi/console/connect) lists everything connected to the account, each with `Disconnect`. Its tokens stop working, streams close, and future app-owned webhook deliveries and rule actions stop. App edits, deletion or secret rotation invalidate existing installations and pending consent. Already-sent mail and in-flight network requests cannot be recalled.

## When a request is refused

An OAuth refusal is not the REST error envelope. It answers `{ "error": "<code>" }`, and most refusals add an `error_description`: a fixed sentence written in the API, never text taken from the request. The description is for a person or a log; a program branches on `error`. An invalid authorization request never redirects.

| Code | Status | When |
| --- | --- | --- |
| `invalid_request` | 400 | A parameter the endpoint reads is missing, malformed, repeated or too long; the resource is not this API's origin or its MCP endpoint; the redirect is not one the client registered; or the body has the wrong content type. |
| `invalid_client` | 400, 401 | The client is not registered here, its registration lapsed, or its authentication failed. The token endpoint answers `401`, which tells a host to register or identify itself again. |
| `invalid_grant` | 400 | The code or refresh token is unknown, expired or already used, or does not match the client, the redirect, the resource or the verifier. |
| `invalid_scope` | 400 | An authorization or token request names a permission this API does not have or names one twice, the client is not registered for it, or a refresh asked for more than it holds. |
| `unsupported_grant_type` | 400 | The grant is neither `authorization_code` nor `refresh_token`. |
| `temporarily_unavailable` | 429 | A rate limit was reached, or too many approvals or unapproved clients are waiting. `Retry-After` says when to try again. |
| `invalid_redirect_uri` | 400 | Registration only: none of the redirects is one this API can use. |
| `invalid_client_metadata` | 400 | The registration is not a JSON object, a field the API reads has the wrong type or is too long, its grants leave out `authorization_code`, or its `scope` names a permission this API does not have or names one twice. Also a Client ID Metadata Document that could not be read or did not check out. |

## Discovery and MCP authorization

The authorization server is [https://api.doorman.fyi/.well-known/oauth-authorization-server](https://api.doorman.fyi/.well-known/oauth-authorization-server). REST uses the resource `https://api.doorman.fyi`; MCP uses `https://api.doorman.fyi/mcp`. These are distinct audiences, so a token for one is refused by the other.

Hosts ask a person for whatever is advertised, so discovery advertises what an agent needs and no more. The authorization-server metadata lists the default agent permissions and `offline_access` under `scopes_supported`, and the MCP resource metadata lists the default agent permissions. The REST resource metadata still lists every app permission, and a client may ask for any of them by name.

An unauthenticated request returns a `WWW-Authenticate` challenge pointing to the matching protected-resource metadata; on the MCP endpoint the challenge also names the default agent permissions. An MCP host can discover it, [register itself or name itself by its metadata document](https://doorman.fyi/docs/oauth.md#clients), then run the same browser consent flow with S256 PKCE.

The remote [MCP server](https://doorman.fyi/docs/mcp.md#connect-http) lists only tools allowed by the app's scopes. Each tool call is checked again against the registry, tenant and resource; hiding a tool is not the authorization boundary. Dynamic registration does not establish a trusted developer identity.
