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 exchangestring
required
The authorization code received from the
/authorize endpointstring
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 refreshstring
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
Bearernumber
Time in seconds until the access token expires (3600 = 1 hour)
string
Refresh token used to obtain new access tokens. Valid for 30 days.
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:Header
Payload
Token Storage Best Practices
Server-Side Applications
Server-Side Applications
Store tokens in secure, HTTP-only cookies or server-side sessions. Never expose client secrets in client-side code.
Token Refresh Strategy
Token Refresh Strategy
Implement proactive token refresh before expiration:
Handle Refresh Token Rotation
Handle Refresh Token Rotation
Always update stored tokens after refresh:
Security Considerations
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
