Overview
The token exchange endpoint converts an authorization code into access tokens and ID tokens. This is the second step in the OAuth 2.0 authorization code flow, after receiving the authorization code from the authorization URL.Endpoint
POST
{SCALEKIT_ENVIRONMENT_URL}/oauth/tokenRequest Headers
Must be
application/x-www-form-urlencodedRequest Parameters
OAuth grant type. Use
authorization_code for exchanging authorization codes.The authorization code received from the authorization callback. This code is single-use and expires after a short period.
Your Scalekit application client ID from the Dashboard.
Your Scalekit application client secret from the Dashboard.
The same redirect URI used in the authorization request. Must match exactly.
Request Examples
Response
JWT access token for making authenticated API requests on behalf of the user.
Always
Bearer for OAuth 2.0 flows.Number of seconds until the access token expires.
JWT ID token containing user identity information. Decode this token to access user claims.
Refresh token for obtaining new access tokens. Only returned if offline_access scope was requested.
Space-separated list of granted OAuth scopes.
Response Example
ID Token Claims
The ID token is a JWT that contains user identity information. Decode the token to access these claims:Unique identifier for the user (subject). Use this as the user ID in your application.
User’s email address. Only present if
email scope was requested.Whether the email address has been verified.
User’s full name. Only present if
profile scope was requested.User’s first name.
User’s last name.
URL of the user’s profile picture.
Token issuer (your Scalekit environment URL).
Token audience (your client_id).
Token issued at timestamp (Unix epoch).
Token expiration timestamp (Unix epoch).
Decoded ID Token Example
Error Responses
Error code indicating the type of error.
Human-readable description of the error.
Common Errors
| Error Code | Description | Solution |
|---|---|---|
invalid_grant | Authorization code is invalid, expired, or already used | Request a new authorization code |
invalid_client | Client authentication failed | Verify client_id and client_secret |
invalid_request | Missing or invalid required parameters | Check all parameters are included |
unsupported_grant_type | Invalid grant_type parameter | Use authorization_code for this flow |
redirect_uri_mismatch | Redirect URI doesn’t match authorization request | Ensure redirect_uri matches exactly |
Error Response Example
Security Considerations
Token Validation
Always validate tokens before using them:Next Steps
Session Management
Manage user sessions and validate tokens
Logout
Implement secure logout functionality