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.
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_sha256lists 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, andtoken_exchange. - 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), callsGET /auth/oauth/requests/{id}and thenapproveordeny. The device page, atoauth.device_page(default:/login/device), callsGET /auth/device/{code}and thenapproveordeny. Both need a signed-in person. - The app’s proxy forwards
/login/oauth/,/login/device/, and/.well-known/besides/auth/.
dev refuses oauth.enabled.