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.
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.
| Field | Required | Description |
|---|---|---|
| client_name | Yes | Human-readable name shown on the consent screen |
| redirect_uris | Yes | Array 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_types | No | Defaults to ["authorization_code", "refresh_token"]. Only these two are supported. |
| response_types | No | Defaults to ["code"]. |
| token_endpoint_auth_method | No | Defaults to none (public client). Other values are rejected. |
Field names and defaults are exact contract values.
| Error code | Cause |
|---|---|
| invalid_client_metadata | Missing client_name or malformed payload |
| invalid_redirect_uri | redirect_uris missing, empty, or contains a URL that doesn't conform to the registration rules |
| invalid_token_endpoint_auth_method | Value other than none requested |
Returned with HTTP 400.
| Parameter | Required | Description |
|---|---|---|
| client_id | Yes | Your registered OAuth client ID |
| redirect_uri | Yes | Must match a registered redirect URI |
| state | Yes | Opaque CSRF token, returned unchanged on the callback |
| scope | No | Space-separated scopes. Defaults to openid |
| response_type | No | Must be code. Defaults to code |
| code_challenge | Required for public clients, optional for confidential | Base64url-encoded SHA-256 hash of the verifier |
| code_challenge_method | Required when code_challenge is present | Must be S256 |
Query-string parameters; exact names and defaults.
| Error code | Cause |
|---|---|
| invalid_client | Unknown client_id |
| invalid_request | Missing parameter, unregistered redirect_uri, or code_challenge_method not S256 |
| invalid_scope | Requested scope not allowed for this client |
| unsupported_response_type | response_type is not code |
Returned with HTTP 400.
| Client type | Method |
|---|---|
| Public | client_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.
| Parameter | Required | Description |
|---|---|---|
| grant_type | Yes | authorization_code |
| code | Yes | The authorization code from the callback |
| redirect_uri | Yes | Must match the URI used in the authorization request |
| client_id | Yes | Via body or Basic auth |
| client_secret | Confidential only | Via body or Basic auth |
| code_verifier | Required if code_challenge was sent at authorize | Original PKCE verifier |
Exact parameter names and requiredness.
| Parameter | Required | Description |
|---|---|---|
| grant_type | Yes | refresh_token |
| refresh_token | Yes | The refresh token from a previous token response |
| client_id | Yes | Via body or Basic auth |
| client_secret | Confidential only | Via body or Basic auth |
Exact parameter names and requiredness.
| Error code | Cause |
|---|---|
| invalid_client | Unknown client_id, incorrect client_secret for a confidential client, or PKCE required but missing |
| invalid_grant | Authorization 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_type | Only authorization_code and refresh_token are supported |
| server_error | Unexpected server-side error |
Returned with HTTP 400.
| Field | Type | Description |
|---|---|---|
| id | string | Account user ID |
| name | string | User's full name |
| string | User's email address |
Exact field names and types.
| Token | Lifetime |
|---|---|
| Access token | 60 minutes |
| ID token | 60 minutes |
| Refresh token | 365 days |
| Authorization code | 10 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]"
}| Status | Error code | Cause |
|---|---|---|
| 401 | unauthorized | Missing or invalid Authorization header |
| 401 | invalid_token | Token is missing required claims |
Exact status codes and error codes.