> Documentation index: https://docs.zernio.com/llms.txt. Every page is also Markdown: add .md to its URL.

# Exchange a code or refresh token API Reference

The token endpoint (RFC 6749). Send `application/x-www-form-urlencoded` (a JSON body is also read). Confidential clients authenticate with `client_secret` in the body (`client_secret_post`) or HTTP Basic (`client_secret_basic`); public clients send only `client_id`.

- `authorization_code`: send `code`, the same `redirect_uri` as the authorization request, and `code_verifier`. A code is single-use and expires after 10 minutes.
- `refresh_token`: send `refresh_token`. Every refresh returns a new refresh token and retires the one you sent. Pass `scope` to narrow the new tokens to a subset of the grant.
- A retired refresh token keeps working for 60 seconds, and after that until its replacement is used, so concurrent refreshes or a lost response do not log the user out.

Responses are sent with `Cache-Control: no-store`.


## POST /oauth/token

**Exchange a code or refresh token**

The token endpoint (RFC 6749). Send `application/x-www-form-urlencoded` (a JSON body is also read). Confidential clients authenticate with `client_secret` in the body (`client_secret_post`) or HTTP Basic (`client_secret_basic`); public clients send only `client_id`.

- `authorization_code`: send `code`, the same `redirect_uri` as the authorization request, and `code_verifier`. A code is single-use and expires after 10 minutes.
- `refresh_token`: send `refresh_token`. Every refresh returns a new refresh token and retires the one you sent. Pass `scope` to narrow the new tokens to a subset of the grant.
- A retired refresh token keeps working for 60 seconds, and after that until its replacement is used, so concurrent refreshes or a lost response do not log the user out.

Responses are sent with `Cache-Control: no-store`.


### Request Body


### Responses

#### 200: Tokens.

**Response Body:**

- **access_token** (required) `string`: Send as Authorization: Bearer. Starts with late_at_.
- **token_type** (required) `string`: No description - one of: bearer
- **expires_in** (required) `integer`: Seconds until the access token expires (3600).
- **refresh_token** (required) `string`: Starts with late_rt_. Lasts 30 days and is replaced by a new one on every refresh.
- **scope** (required) `string`: Space-separated scopes the tokens carry.

#### 400: `invalid_request`, `invalid_grant` (code used, expired or not this client; redirect_uri mismatch; PKCE verification failed; refresh token revoked or expired), `invalid_scope`, `invalid_target` or `unsupported_grant_type`.

**Response Body:**

- **error** (required) `string`: invalid_request, invalid_client, invalid_grant, invalid_scope, invalid_target, unsupported_grant_type, invalid_client_metadata, invalid_redirect_uri, invalid_token, too_many_requests or server_error.
- **error_description** `string`: Human-readable detail.

#### 401: `invalid_client`: wrong or missing client_secret for a confidential client. With HTTP Basic the response carries `WWW-Authenticate: Basic`.

**Response Body:**

- **error** (required) `string`: invalid_request, invalid_client, invalid_grant, invalid_scope, invalid_target, unsupported_grant_type, invalid_client_metadata, invalid_redirect_uri, invalid_token, too_many_requests or server_error.
- **error_description** `string`: Human-readable detail.

---


# Related Schema Definitions

## OAuthTokenResponse

### Properties

- **access_token** (required) `string`: Send as Authorization: Bearer. Starts with late_at_.
- **token_type** (required) `string`: No description - one of: bearer
- **expires_in** (required) `integer`: Seconds until the access token expires (3600).
- **refresh_token** (required) `string`: Starts with late_rt_. Lasts 30 days and is replaced by a new one on every refresh.
- **scope** (required) `string`: Space-separated scopes the tokens carry.

## OAuthError

Error body of the OAuth endpoints (RFC 6749 section 5.2).

### Properties

- **error** (required) `string`: invalid_request, invalid_client, invalid_grant, invalid_scope, invalid_target, unsupported_grant_type, invalid_client_metadata, invalid_redirect_uri, invalid_token, too_many_requests or server_error.
- **error_description** `string`: Human-readable detail.