# OAuth and the device flow

> Run the server as an OAuth 2.0 and OpenID Connect provider, for a CLI that signs in with the device flow or for an MCP client.

From `README.md`, `docs/server.md` in tensile-tools/tensile-auth at commit `e66760d` (v0.4.1-7-ge66760d). The HTML page is https://auth.tensile.tools/docs/guides/oauth.

The provider has the device flow, the code flow with PKCE, rotating refresh tokens, and token exchange onto delegation. `gh auth login --hostname` works against it, and `examples/ghserver` is a minimal GitHub-compatible server that the gh CLI signs in to.

With `oauth.enabled`, the server is an OAuth 2.0 and OpenID Connect provider, for example for a CLI that signs in with the device flow or an MCP client.

```toml
[oauth]
enabled = true

[[oauth.clients]]
id = "my-cli"
name = "My CLI"
native = true
grants = ["device_code", "refresh_token"]
scopes = ["repo"]

[[oauth.clients]]
id = "dashboard"
name = "Dashboard"
secret_sha256 = ["9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"]
redirect_uris = ["https://dashboard.example.com/callback"]
grants = ["authorization_code", "refresh_token"]

[[oauth.resources]]
uri = "https://app.example.com/mcp"
name = "Notes MCP server"
scopes = ["notes.read"]
```

- **Clients and resources come only from the file.** They have no variables or flags.
- **The file holds no client secret.** `secret_sha256` lists the hex SHA-256 of each valid secret: `printf %s "$SECRET" | sha256sum`. A client without one is public.
- **Grants** are `authorization_code`, `refresh_token`, `device_code`, and `token_exchange`.
- **A resource's `uri`** is the MCP server's canonical URI. It must use `https://`, except on a loopback host, such as `http://localhost:3000/mcp`, for development.
- **A token gets only scopes the person holds.** Approval grants the scopes that the approving session holds, so a resource's `scopes` reach a token only when sessions carry them: set `sessions.default_scopes`, or answer them from the `session_scopes` hook.
- **The issuer** defaults to the first origin, and must use `https://` outside localhost. The provider signs with the server's OpenID Connect key, and serves the key set at `/login/oauth/keys`, with the next and previous keys during a rotation.
- **The app serves two pages.** The consent page, at `oauth.interaction` (default: the first origin and `/oauth/consent`), calls `GET /auth/oauth/requests/{id}` and then `approve` or `deny`. The request ID arrives in the page's `request` query parameter. Show `granted_scopes`, and say that the app doesn't get `withheld_scopes`. The device page, at `oauth.device_page` (default: `/login/device`), calls `GET /auth/device/{code}` and then `approve` or `deny`. Both need a signed-in person.
- **The app's proxy forwards** `/login/oauth/`, `/login/device/`, and `/.well-known/` besides `/auth/`.

`dev` refuses `oauth.enabled`.
