Skip to main content

Overview

The token endpoint is used to exchange an authorization code for access tokens, or to refresh an expired access token using a refresh token.

Request Body

Content-Type: application/json

Authorization Code Grant

string
required
Must be authorization_code for code exchange
string
required
The authorization code received from the /authorize endpoint
string
required
The PKCE code verifier that was used to generate the code challenge
string
required
The same redirect URI used in the authorization request
string
required
Your OAuth client ID
string
required
Your OAuth client secret

Refresh Token Grant

string
required
Must be refresh_token for token refresh
string
required
The refresh token received in a previous token response
string
required
Your OAuth client ID
string
required
Your OAuth client secret

Response

Success (200 OK)

string
JWT access token used to authenticate API requests. Valid for 1 hour.
string
Always Bearer
number
Time in seconds until the access token expires (3600 = 1 hour)
string
Refresh token used to obtain new access tokens. Valid for 30 days.
Refresh tokens are automatically rotated. The old refresh token is revoked when you use it, and a new one is issued.
string
Space-separated list of granted scopes

Error (400 / 401)

Error Codes

Example Requests

Token Lifecycle

1

Authorization Code Exchange

Exchange the authorization code for initial access and refresh tokens. Authorization codes expire after 10 minutes.
2

Use Access Token

Use the access token to make authenticated API requests. Access tokens are valid for 1 hour.
3

Refresh When Expired

When the access token expires, use the refresh token to get new tokens. Refresh tokens are valid for 30 days.
4

Automatic Rotation

Each refresh generates new access and refresh tokens. The old refresh token is automatically revoked.

Access Token Structure

Access tokens are JWTs (JSON Web Tokens) with the following structure:

Payload

Token Storage Best Practices

Store tokens in secure, HTTP-only cookies or server-side sessions. Never expose client secrets in client-side code.
Implement proactive token refresh before expiration:
Always update stored tokens after refresh:

Security Considerations

Never expose client secrets in client-side code. Token exchange should always happen server-side.
Refresh token rotation - Old refresh tokens are revoked immediately upon use. Always store the new refresh token from the response.
PKCE validation - The code_verifier must match the code_challenge used in the authorization request, or the token exchange will fail.

Next Steps

Get User Info

GET /userinfo - Retrieve user information

Introspect Token

POST /introspect - Validate and inspect tokens

Revoke Token

POST /revoke - Revoke access or refresh tokens

Integration Guide

Learn about integration patterns