OAuth Flow Endpoints

These are the OAuth 2.0 protocol endpoints clients use to obtain access tokens and revoke them. They implement RFC 6749 (OAuth 2.0 Authorization Framework), RFC 7009 (Token Revocation), RFC 7636 (PKCE), and RFC 8707 (Resource Indicators).

All endpoints are mounted on the public blueprint and require no bearer token. The locations are also advertised by the OAuth Discovery endpoints so clients can configure themselves automatically.

Endpoints

Method Endpoint Description
GET, POST /oauth/authorize Begin an authorization code flow
POST /oauth/token Exchange a code, refresh token, or credentials for an access token
POST /oauth/revoke Revoke a refresh token

Authorization Endpoint

GET /public/v2/oauth/authorize
POST /public/v2/oauth/authorize

Browser-redirect endpoint that initiates the authorization code grant. The user is asked to log in (if not already authenticated via an OAuth session cookie) and then to grant or deny consent. On success the user-agent is redirected to the client’s redirect_uri with an authorization code query parameter.

Query Parameters

Parameter Type Required Description
client_id string Yes Client identifier issued during client registration, or the HTTPS URL of a client metadata document
redirect_uri string Yes Redirect URI registered for this client. Must exactly match a registered URI, except that a plain-HTTP loopback URI (localhost, 127.0.0.1, ::1) may use any port (RFC 8252 §7.3), for native clients that listen on a free port
response_type string Yes Must be code. Any other value redirects with error=unsupported_response_type
scope string No Space-separated list of requested scopes: read, write, or both. When omitted, the client’s registered scope is requested (read write unless it registered something narrower)
state string No Opaque value echoed back on redirect so the client can correlate the request and defend against CSRF
resource string No RFC 8707 resource indicator. If supplied, the same value must be sent to the token endpoint and will be bound as the access token’s audience
code_challenge string Yes PKCE code challenge derived from the client’s code_verifier. PKCE is mandatory — every authorization request must include one
code_challenge_method string No PKCE method used to derive code_challenge. Only S256 is supported (default when omitted); any other value is rejected

Form Parameters (POST)

When the user submits the consent form, the endpoint accepts:

Field Type Description
csrf_token string The token rendered into the consent form. A missing or wrong token answers 400 {"error": "invalid_request"}
confirm string yes to issue an authorization code, anything else to deny
grant_write string yes to keep write in the granted scope. The consent screen shows write as a pre-ticked checkbox whenever it is requested; unticking it (the field is then absent) grants the requested scope without write, i.e. read

The scope the user approves is bound to the authorization code and becomes the scope of the tokens issued for it. A read-only token cannot gain write later; the user has to authorize again.

Successful Response

The user-agent is redirected to:

{redirect_uri}?code={authorization_code}&state={state}&iss={issuer}

state is included only when the original request supplied one. The code is single-use and short-lived.

Every redirect back to the client, success or error, carries iss (RFC 9207): the server’s issuer URL, the same value as issuer in the authorization server metadata. A client that talks to several authorization servers should check it before redeeming the code. If the registered redirect_uri already has a query string, the parameters are appended to it.

Denial Response

If the user denies access, the user-agent is redirected to:

{redirect_uri}?error=access_denied&state={state}&iss={issuer}

Error Responses

Status Response Description
400 {"error": "invalid_request"} Missing client_id or redirect_uri
400 {"error": "invalid_client"} Unknown client_id, or a metadata document URL that cannot be fetched or is not an acceptable public client
400 {"error": "invalid_request"} Consent form posted without a valid csrf_token
400 {"error": "invalid_redirect_uri"} The supplied redirect_uri is not registered for this client
302 Redirect with error=unsupported_response_type response_type is not code
302 Redirect with error=invalid_request&error_description=PKCE+with+code_challenge_method%3DS256+is+required code_challenge is missing, or code_challenge_method is set to anything other than S256
302 Redirect with error=invalid_scope&error_description=Supported+scopes%3A+read%2C+write scope contains a value other than read or write
429 Rate limit response More than 120 requests per hour

Client ID Metadata Documents

Instead of registering first, a client may use the HTTPS URL of its own client metadata document (draft-ietf-oauth-client-id-metadata-document) as its client_id. The discovery metadata advertises this with client_id_metadata_document_supported: true.

The server fetches the document on first use and again when the cached copy is more than a day old; if a refetch fails, the last good copy keeps being used. The document must:

  • be served at the client_id URL itself (HTTPS, a non-root path, no fragment or credentials) from a public address, with status 200, without redirects, as a JSON object of at most 5 KB, within 5 seconds
  • name the same URL in its client_id field
  • describe a public client: no client_secret, and none as its token_endpoint_auth_method or among its token_endpoint_auth_methods_supported
  • list at least one redirect_uris entry, each HTTPS or plain HTTP on a loopback host
  • include authorization_code in grant_types (defaults to authorization_code and refresh_token; other grant types are ignored)

client_name is shown on the consent screen, together with the document’s host. Such a client gets the read write scope and authenticates at the token endpoint with its client_id URL alone.

Login Flow

If the user is not authenticated when the endpoint is reached, the response is a 302 to /public/v2/oauth/login with the original authorize URL preserved in the next query parameter. After successful login the user-agent is sent back to the authorize endpoint and the consent form is shown.


Token Endpoint

POST /public/v2/oauth/token

Returns a bearer access token. Supports three grant types — authorization_code, refresh_token, and client_credentials. The request body is application/x-www-form-urlencoded.

Client Authentication

A confidential client authenticates either by including client_id and client_secret in the form body (client_secret_post) or by HTTP Basic auth (client_secret_basic). A public client — one registered with token_endpoint_auth_method: none, or a client metadata document client — sends its client_id alone; PKCE binds its authorization code to it. All three methods are advertised by the discovery endpoint.

Common Form Parameters

Field Type Required Description
grant_type string Yes One of authorization_code, refresh_token, client_credentials
client_id string Conditional Required when not using HTTP Basic auth
client_secret string Conditional Required for confidential clients when not using HTTP Basic auth. Omitted by public clients

The grant type must be listed in the client’s registered grant_types; otherwise the response is 400 {"error": "unauthorized_client"}.

Grant: authorization_code

Exchanges a single-use authorization code obtained from the authorize endpoint for an access token and a refresh token.

Field Type Required Description
code string Yes The authorization code received on the redirect URI
redirect_uri string Yes Must exactly match the redirect_uri sent to the authorize endpoint
code_verifier string Yes The PKCE verifier for the code_challenge sent to the authorize endpoint. Every authorization request carries a challenge, so every exchange needs it
resource string Conditional Required when the authorization request included a resource parameter, and must equal that value

Response

{
  "access_token": "<access_token>",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "<refresh_token>",
  "scope": "read write"
}

Grant: refresh_token

Exchanges a refresh token for a new access token. Refresh tokens are rotated — the old token is revoked and a new one is returned.

Field Type Required Description
refresh_token string Yes A valid, unrevoked refresh token issued to this client
scope string No A subset of the originally granted scopes. Defaults to the original scope when omitted
resource string No RFC 8707 resource indicator to bind as the audience of the new access token

Response

Same shape as the authorization_code response. The refresh_token field contains the rotated refresh token — clients must store it and discard the previous one.

Grant: client_credentials

Server-to-server flow. The token is associated with the client’s owning user.

Field Type Required Description
scope string No Space-separated list of requested scopes. Narrowed to the client’s registered scope; defaults to the full registered scope when omitted
resource string No RFC 8707 resource indicator to bind as the audience of the access token

Response

{
  "access_token": "<access_token>",
  "token_type": "Bearer",
  "expires_in": 3600,
  "scope": "read write"
}

No refresh_token is issued for the client credentials grant — clients re-request a token as needed.

Error Responses

Status Body Description
401 {"error": "invalid_client"} Missing or incorrect client credentials, or a confidential client sent no secret
400 {"error": "unauthorized_client"} The grant type is not enabled for this client
400 {"error": "unsupported_grant_type"} The grant_type value is not recognised
400 {"error": "invalid_grant", "error_description": "Authorization code is required"} code missing on an authorization_code request
400 {"error": "invalid_grant", "error_description": "Invalid authorization code"} Code not found
400 {"error": "invalid_grant", "error_description": "Authorization code expired"} Code TTL elapsed
400 {"error": "invalid_grant", "error_description": "Authorization code was issued to another client"} Cross-client code reuse attempt
400 {"error": "invalid_grant", "error_description": "Redirect URI mismatch"} redirect_uri does not match the original authorize request
400 {"error": "invalid_grant", "error_description": "Code verifier is required"} PKCE expected but code_verifier not supplied
400 {"error": "invalid_grant", "error_description": "Code verifier is invalid"} PKCE verifier does not match the original challenge
400 {"error": "invalid_grant", "error_description": "Resource parameter is required"} resource was sent at authorize but missing at token exchange
400 {"error": "invalid_grant", "error_description": "Resource parameter mismatch"} resource value differs from the authorize request
400 {"error": "invalid_grant", "error_description": "Refresh token is required"} refresh_token missing
400 {"error": "invalid_grant", "error_description": "Invalid refresh token"} Refresh token not found, expired, or revoked
400 {"error": "invalid_grant", "error_description": "Refresh token was issued to another client"} Cross-client refresh attempt
429 Rate limit response More than 60 requests per minute

Revocation Endpoint

POST /public/v2/oauth/revoke

Revokes a token per RFC 7009. Only refresh tokens are durably revocable — access tokens are short-lived JWTs and are not tracked server-side, so revoking one returns success without effect.

The request body is application/x-www-form-urlencoded.

Form Parameters

Field Type Required Description
token string Yes The token to revoke
token_type_hint string No refresh_token or access_token. The server still looks the token up if the hint is wrong, per RFC 7009
client_id string Conditional Required when not using HTTP Basic auth
client_secret string Conditional Required for confidential clients when not using HTTP Basic auth. Omitted by public clients

Response

Returns 200 OK with an empty JSON body on success, including when the token is unknown — the spec requires that revocation requests for invalid tokens still succeed so that clients cannot probe for token existence.

{}

A refresh token is only actually revoked when both:

  • The token is recognised.
  • The token belongs to the authenticated client.

If those conditions are not met the response is still 200 {}.

Error Responses

Status Body Description
400 {"error": "invalid_request"} token field is missing
401 {"error": "invalid_client"} Missing or incorrect client credentials
429 Rate limit response More than 60 requests per minute

  • OAuth Discovery — well-known metadata endpoints that advertise these URLs
  • OAuth Clients — register and manage OAuth client applications
  • OAuth Admin — admin endpoints for listing and revoking tokens across users