Skip to content

OAuth2 Endpoints Reference

This reference walks through every OAuth2 route a client needs: metadata discovery, dynamic registration, the authorization redirect, token exchange and refresh, and the userinfo call. Each section lists the parameters, the success payload and the error codes so you can match a failing request to its cause.

Base URL and compatibility host

All routes in this reference are relative to the canonical base URL shown in the configuration block. The original host $API_APP_BASE_URL/oauth/* remains a permanent compatibility mapping onto the same routes for the legacy flow; every endpoint below behaves identically on both hosts, and the examples use the canonical URL.

GET /.well-known/oauth-authorization-server

This is the RFC 8414 authorization server metadata document. OAuth libraries that support RFC 8414 can discover every other endpoint and capability from this URL without hard-coded addresses. A 200 response returns the metadata object shown in the protected JSON module, including the supported response types, grant types, PKCE methods, client authentication methods and scopes.

The issuer value points at the identity provider behind the service rather than at the auth host itself. Tokens issued by /oauth/token embed that identical string in their iss claim, so a client that compares the JWT issuer with the metadata issuer finds a matching pair and treats the token as valid.

POST /oauth/register

Dynamic Client Registration (RFC 7591) registers a public client without human intervention. MCP clients such as Claude Desktop and Cursor use it on first launch. The request body carries client_name and redirect_uris; grant_types, response_types and token_endpoint_auth_method are optional and default as described in the registration field table. A successful registration returns 201 with a client_id and echoes the registered metadata. No client_secret is returned because PKCE replaces it.

Registration rate limits and errors

Registration is rate-limited per source IP to prevent abuse. A client that registers once on install stays well under the limit; repeated re-registration from the same IP will be throttled. A 400 response returns an error code and description. The registration error table maps invalid_client_metadata, invalid_redirect_uri and invalid_token_endpoint_auth_method to their causes.

GET /oauth/authorize

This route starts the authorization code flow; redirect the user's browser here. The query string requires client_id, redirect_uri and state, with optional scope, response_type, code_challenge and code_challenge_method. A successful request returns a 302 to the login and consent page; after consent the user returns to your redirect_uri with a code and the state you sent. A 400 response returns one of the error codes in the authorize error table.

POST /oauth/token

The token endpoint exchanges an authorization code for tokens or refreshes an existing token. It accepts application/x-www-form-urlencoded (standard) and application/json. Client authentication depends on client type: public clients send client_id in the body with no secret and a PKCE code_verifier; confidential clients send client_id and client_secret as form fields or via HTTP Basic. Confidential clients may also send code_verifier, and if a code_challenge was sent at authorize the server validates it.

Authorization code exchange

The exchange request requires grant_type=authorization_code, code, redirect_uri and client_id; client_secret is required only for confidential clients, and code_verifier is required if a code_challenge was sent at authorize. A 200 response returns access_token, id_token, refresh_token, token_type Bearer and expires_in 3600.

Token refresh

A refresh request requires grant_type=refresh_token, refresh_token and client_id; client_secret is required only for confidential clients. A 200 response returns access_token, refresh_token, token_type Bearer and expires_in 3600. The same refresh token is echoed back, no id_token is included in refresh responses, and refresh tokens are not rotated.

Token errors and response headers

A 400 response returns one of invalid_client, invalid_grant, unsupported_grant_type or server_error with a human-readable description. The token error table maps each code to its cause. All token responses include Cache-Control: no-store and Pragma: no-cache.

GET /oauth/me

The userinfo endpoint returns basic profile information for the authenticated user. It requires a valid access token in the Authorization header as a Bearer token. A 200 response returns id, name and email as described in the userinfo field table. A 401 response returns unauthorized when the Authorization header is missing or invalid, or invalid_token when the token is missing required claims.

Token lifetimes

Access tokens and ID tokens last 60 minutes. Refresh tokens last 365 days. Authorization codes last 10 minutes and are single-use.

Integration checklist

Use this checklist to keep the endpoints aligned with your client type:

  • Confirm whether your client is public or confidential before choosing an authentication method at the token endpoint.
  • For public clients, generate a PKCE verifier, send its S256 challenge at authorize, and send the verifier at token exchange.
  • Register loopback redirect URIs with http://127.0.0.1:{port} so the port-agnostic matching rule applies; all other redirect URIs must match exactly.
  • Send state at authorize and verify it on the callback.
  • Expect no id_token on refresh responses and no refresh token rotation.
  • Cache-Control: no-store and Pragma: no-cache are present on every token response, so do not cache token payloads.
  • Distinguish invalid_client (client identity or PKCE requirement) from invalid_grant (code, redirect_uri, client_id or verifier mismatch) when debugging a 400 at the token endpoint.
Dynamic client registration fields
FieldRequiredDescription
client_nameYesHuman-readable name shown on the consent screen
redirect_urisYesArray of allowed redirect URIs. Loopback (http://127.0.0.1:{port}) is matched port-agnostically per RFC 8252; all other URIs must match exactly.
grant_typesNoDefaults to ["authorization_code", "refresh_token"]. Only these two are supported.
response_typesNoDefaults to ["code"].
token_endpoint_auth_methodNoDefaults to none (public client). Other values are rejected.

Field names and defaults are exact contract values.

Registration error codes
Error codeCause
invalid_client_metadataMissing client_name or malformed payload
invalid_redirect_uriredirect_uris missing, empty, or contains a URL that doesn't conform to the registration rules
invalid_token_endpoint_auth_methodValue other than none requested

Returned with HTTP 400.

Authorize request parameters
ParameterRequiredDescription
client_idYesYour registered OAuth client ID
redirect_uriYesMust match a registered redirect URI
stateYesOpaque CSRF token, returned unchanged on the callback
scopeNoSpace-separated scopes. Defaults to openid
response_typeNoMust be code. Defaults to code
code_challengeRequired for public clients, optional for confidentialBase64url-encoded SHA-256 hash of the verifier
code_challenge_methodRequired when code_challenge is presentMust be S256

Query-string parameters; exact names and defaults.

Authorize error codes
Error codeCause
invalid_clientUnknown client_id
invalid_requestMissing parameter, unregistered redirect_uri, or code_challenge_method not S256
invalid_scopeRequested scope not allowed for this client
unsupported_response_typeresponse_type is not code

Returned with HTTP 400.

Token endpoint client authentication
Client typeMethod
Publicclient_id in body; no secret; PKCE code_verifier required
Confidential (body)client_id + client_secret as form fields
Confidential (Basic)Authorization: Basic base64(client_id:client_secret)

Exact authentication method strings.

Authorization code exchange parameters
ParameterRequiredDescription
grant_typeYesauthorization_code
codeYesThe authorization code from the callback
redirect_uriYesMust match the URI used in the authorization request
client_idYesVia body or Basic auth
client_secretConfidential onlyVia body or Basic auth
code_verifierRequired if code_challenge was sent at authorizeOriginal PKCE verifier

Exact parameter names and requiredness.

Token refresh parameters
ParameterRequiredDescription
grant_typeYesrefresh_token
refresh_tokenYesThe refresh token from a previous token response
client_idYesVia body or Basic auth
client_secretConfidential onlyVia body or Basic auth

Exact parameter names and requiredness.

Token endpoint error codes
Error codeCause
invalid_clientUnknown client_id, incorrect client_secret for a confidential client, or PKCE required but missing
invalid_grantAuthorization code is invalid, expired, or already used. redirect_uri / client_id mismatch. Refresh token invalid/expired. PKCE verifier does not match the challenge.
unsupported_grant_typeOnly authorization_code and refresh_token are supported
server_errorUnexpected server-side error

Returned with HTTP 400.

Userinfo response fields
FieldTypeDescription
idstringAccount user ID
namestringUser's full name
emailstringUser's email address

Exact field names and types.

Token lifetimes
TokenLifetime
Access token60 minutes
ID token60 minutes
Refresh token365 days
Authorization code10 minutes (single-use)

Exact numeric lifetimes.

Frequently asked questions

How does a client discover the OAuth2 endpoints?

Libraries with RFC 8414 support read the metadata document at GET /.well-known/oauth-authorization-server and obtain the authorization, token, registration and userinfo URLs from it, so no endpoint URLs need to be hard-coded.

Why does the metadata issuer differ from the auth host?

The issuer value is the URL of the underlying identity provider, not {{AUTH_BASE_URL}}. The JWTs returned by /oauth/token carry the same value in their iss claim, so clients that cross-check the JWT issuer against the metadata response accept them.

Does dynamic registration return a client secret?

No. Registration returns a client_id and echoes the registered metadata; PKCE replaces the client secret for public clients.

Are refresh tokens rotated?

No. The same refresh token is echoed back in the refresh response, and no id_token is included.

What causes invalid_grant at the token endpoint?

An authorization code that is invalid, expired or already used; a redirect_uri or client_id mismatch; an invalid or expired refresh token; or a PKCE verifier that does not match the challenge.

What do the two 401 responses from /oauth/me mean?

unauthorized means the Authorization header is missing or invalid. invalid_token means the token is present but missing required claims.

{{AUTH_BASE_URL}}
{
  "issuer": "<opaque identity-provider URL>",
  "authorization_endpoint": "{{AUTH_BASE_URL}}/oauth/authorize",
  "token_endpoint": "{{AUTH_BASE_URL}}/oauth/token",
  "registration_endpoint": "{{AUTH_BASE_URL}}/oauth/register",
  "userinfo_endpoint": "{{AUTH_BASE_URL}}/oauth/me",
  "response_types_supported": ["code"],
  "grant_types_supported": ["authorization_code", "refresh_token"],
  "code_challenge_methods_supported": ["S256"],
  "token_endpoint_auth_methods_supported": ["client_secret_basic", "client_secret_post", "none"],
  "scopes_supported": ["openid", "email", "profile", "mcp:workspace:read", "mcp:users:read", "mcp:leaves:read", "zapier:webhooks"]
}
{
  "client_name": "My Desktop App",
  "redirect_uris": ["http://127.0.0.1:53126/callback"]
}
{
  "client_id": "6a8cd456-...",
  "client_name": "My Desktop App",
  "redirect_uris": ["http://127.0.0.1:53126/callback"],
  "grant_types": ["authorization_code", "refresh_token"],
  "response_types": ["code"],
  "token_endpoint_auth_method": "none"
}
{ "error": "invalid_redirect_uri", "error_description": "…" }
{
  "error": "invalid_client | invalid_request | invalid_scope | unsupported_response_type",
  "error_description": "Human-readable description"
}
{
  "access_token": "eyJ...",
  "id_token": "eyJ...",
  "refresh_token": "eyJ...",
  "token_type": "Bearer",
  "expires_in": 3600
}
{
  "access_token": "eyJ...",
  "refresh_token": "eyJ...",
  "token_type": "Bearer",
  "expires_in": 3600
}
{
  "error": "invalid_client | invalid_grant | unsupported_grant_type | server_error",
  "error_description": "Human-readable description"
}
{
  "id": "vt-user-123",
  "name": "Jane Doe",
  "email": "[email protected]"
}
Userinfo error responses
StatusError codeCause
401unauthorizedMissing or invalid Authorization header
401invalid_tokenToken is missing required claims

Exact status codes and error codes.