# Proofline auth.md

An agent gets a Proofline credential only through a person who approves it. Proofline has no self-service agent registration: an agent cannot create a Proofline account or an organization. A person with a Proofline account signs in with GitHub, chooses the organization, scopes and repositories, and approves the agent's request in a browser.

Every credential is a bearer token sent in the `Authorization` header. It acts with its holder's current GitHub identity and access, only in the organizations, scopes and repositories the person approved. The server checks each request against them; nothing an agent sends widens them.

## Choose a credential

| Credential | Who approves it | Where it works | Organizations | Can change settings |
| --- | --- | --- | --- | --- |
| MCP OAuth | The person, on Proofline's consent page | The MCP server only; REST API routes refuse it | One or more, each with its own scopes and repositories | Through MCP, when an administrator approved `setup:write` or `org:configure` |
| CLI device sign-in | The person, on the device verification page | The REST API and the MCP server | The one organization approved | Through MCP, when an administrator approved `setup:write` or `org:configure` |
| Personal or organization API token | A person, or an administrator for an organization token, in the console | The REST API and the MCP server | The one organization it was created in | No |

A personal or organization API token reads or requests reviews. It never changes configuration, billing, seats, cloud access, integrations or other tokens, and neither does direct REST API access with any credential: the console's configuration routes need a signed-in browser.

## MCP clients: OAuth with dynamic client registration

For the MCP server at `https://proofline.sh/mcp` (Streamable HTTP).

1. An unauthenticated request to `/mcp` returns 401 with a `WWW-Authenticate` header naming the protected resource metadata, `https://proofline.sh/.well-known/oauth-protected-resource/mcp`.
2. That document names the authorization server, `https://proofline.sh`. Its metadata is at `https://proofline.sh/.well-known/oauth-authorization-server` and lists the endpoints and scopes.
3. Register a public client at `/oauth/register` (RFC 7591). Clients do not authenticate at the token endpoint.
4. Send the person to `/oauth/authorize` with the authorization code flow and a PKCE `S256` challenge. The person signs in and approves on Proofline's consent page, where they can add more organizations and choose scopes and repositories for each.
5. Exchange the code at `/oauth/token`. The response carries an access token and a refresh token; a grant for one organization also returns its `organization_id`. Renew the access token as [Renew and reconnect an MCP connection](#renew-and-reconnect-an-mcp-connection) describes.

A tool call that lacks a scope the tool supports is refused with a challenge that requests the scope through consent.

## Renew and reconnect an MCP connection

A `401` from `/mcp` says which case the client is in through its `WWW-Authenticate` header:

- **No `error` parameter.** The request carried no bearer. Start the discovery flow above.
- **`error="invalid_token"`.** The server rejected the bearer it was sent: the access token expired or was revoked. Refresh once, then retry the request with the new access token.

To refresh, `POST /oauth/token` with a form body:

```
grant_type=refresh_token
client_id=<the registered client_id>
refresh_token=<the stored refresh token>
resource=<the same resource the authorization used, the MCP server's URL>
```

An optional `scope` narrows the scopes; it never adds one. The response has the same fields as the code exchange, including a new `refresh_token`. Each refresh rotates the credential: the refresh token just sent is spent, and only the replacement renews the connection again.

**Keep one refresh at a time.** Every process that shares a connection must take a lock before refreshing, store the replacement durably before it releases the lock, and read the stored credential again instead of refreshing a second time. A spent refresh token sent again is treated as stolen: the server revokes the connection's grants, including the access token the first refresh just returned, and answers `invalid_grant`.

**When the person must reconnect.** Refresh answers `invalid_grant` when the refresh token was already spent, the connection was revoked, the person no longer has access, or the connection reached the end of its lifetime, which a shorter [key policy](https://proofline.sh/docs/authentication/#organization-key-policy) can bring forward. A client that lost the replacement before storing it cannot recover the connection: sending the old refresh token revokes it. In each case, do not retry the refresh. Discard the stored credential and send the person through authorization again, where they choose the organizations, scopes and repositories on the consent page as in step 4.

**Connections with several organizations.** One refresh token covers every organization the person approved, and each organization is renewed on its own. When one organization revoked the connection or no longer admits the person, the refresh still succeeds for the others: the replacement covers only those, and its `scope` is theirs. Until that refresh, the current access token keeps working in the other organizations, and calls that name the revoked one are refused. Call `list_organizations` after a refresh to read which organizations remain, and see [Organization selection](#organization-selection) for choosing among them. When no organization remains, refresh answers `invalid_grant`. To use a dropped organization again, the person reconnects and approves it.

## Organization selection

A grant for one organization needs no selection. For a grant that covers several organizations, call the `list_organizations` tool: each entry has an `organization_id` and the scopes granted there. Pass the chosen `organization_id` in each tool call's arguments; it applies to that call only. A call without one returns `ORGANIZATION_REQUIRED`, and a target outside the grant returns `NOT_AUTHORIZED`. Proofline never picks an organization for the agent. See [Organization selection](https://proofline.sh/docs/authentication/#organization-selection).

## Command-line agents: device sign-in

The Proofline CLI signs in with `proofline login`, and `proofline agent install` connects Codex, Cursor, Gemini CLI and Kiro to the MCP server without putting a credential in their configuration. See [Coding agents](https://proofline.sh/docs/coding-agents/).

Another command-line tool can use the same device flow (RFC 8628): `POST /auth/device/code` with the scopes it wants, show the person the verification page, and poll `POST /auth/device/token` until they approve. The response carries an `access_token` and the `organization_id` it works in. See [Device sign-in](https://proofline.sh/docs/authentication/#device-sign-in).

## Scripts and services: API tokens

A person creates a personal token, or an administrator creates an organization token, in the Proofline console. The console shows its secret once. See [Authentication](https://proofline.sh/docs/authentication/) for token kinds, lifetimes, scopes and errors.

## Setup and configuration through MCP

An organization administrator can delegate setup and ordinary configuration to an agent. They approve an MCP OAuth grant or a CLI device sign-in that has no repository restriction and holds `setup:write`, `org:configure` or both, in a browser where they signed in within the last 24 hours. Only an organization administrator can approve `org:configure`, and the organization's API token policy must allow each scope. See [Set up Proofline from your agent](https://proofline.sh/docs/coding-agents/#set-up-proofline-from-your-agent) and [Change settings from your agent](https://proofline.sh/docs/coding-agents/#change-settings-from-your-agent).

The delegated tools act for the approving administrator's browser session and stay within that person's current authority. Each call runs the setting's own permission checks. Signing out of that session ends the delegation; the credential keeps its other scopes.

- **Ordinary settings.** With `org:configure`, the agent reads a setting with `describe_operation`, records the change with `propose_change` and applies it with `apply_change`.
- **Sensitive settings**, such as cloud access, integrations and billing. The agent can only propose the change. Nothing changes until an organization administrator approves that exact change in a browser signed in within the last 24 hours. `org:configure` never approves it. See [Approve sensitive changes](https://proofline.sh/docs/coding-agents/#approve-sensitive-changes).
- **Console-only settings**, such as the merge gate. A person changes them in the console.

`list_operations` marks each setting `apply`, `approval` or `console_only`, so the agent can tell the person which steps are theirs before it starts.

## Revocation

Personal tokens, CLI device tokens and MCP OAuth credentials are revoked from **Personal tokens** in the account menu, and organization tokens from the organization's **API tokens** settings. Revocation takes effect on the token's next request. Revoking an MCP OAuth credential also ends its grant, so the client cannot refresh it.
