Exchange Credentials
Exchange credentials for an access token using one of the supported OAuth2 grant types.
Endpoint
/api/v1/tokensMethod
POST
Headers
| Header | Required | Description |
|---|---|---|
Content-Type | Yes | application/x-www-form-urlencoded |
Authorization | Conditional | Required for client_credentials grant. Must be a Base64-encoded Basic auth header: Basic base64(client_id:client_secret) |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
grant_type | string | Yes | One of: authorization_code, refresh_token, client_credentials |
client_id | string | Conditional | Required when grant_type is authorization_code or refresh_token |
authorization_code | string | Conditional | Required when grant_type is authorization_code |
redirect_uri | string | Conditional | Required when grant_type is authorization_code |
code_verifier | string | Conditional | Required when grant_type is authorization_code (PKCE) |
refresh_token | string | Conditional | Required when grant_type is refresh_token |
state | string | No | Optional state parameter |
Examples
Authorization Code Grant
curl --request POST \
--url https://auth.roled.io/api/v1/tokens \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'authorization_code=6qxJpdxpyuAoSpfzkEbJUpJvBoncYM3Cnxfmj4WznZty7...' \
--data-urlencode 'client_id=2JRYkzSeBV89itqcU9mraF' \
--data-urlencode 'code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk...' \
--data-urlencode 'redirect_uri=https://example.com/auth/callback' \
--data-urlencode 'state=e5384378-26b2-45ae-b6a8-3a569a4bff7d'Client Credentials Grant
curl --request POST \
--url https://auth.roled.io/api/v1/tokens \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic MkpVjd5QzdnV0V1enU4QlRFWG9ZNTpzZWNfQmFja...' \
--data-urlencode 'grant_type=client_credentials'Refresh Token Grant
curl --request POST \
--url https://auth.roled.io/api/v1/tokens \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=refresh_token' \
--data-urlencode 'client_id=2JRYkzSeBV89itqcU9mraF' \
--data-urlencode 'refresh_token=M8MmHrhqzcBgUwCQ5enp4wTuRVBgi2txChS44Q3FYJGRgzX...'Error Codes
| Code | HTTP Status | Description |
|---|---|---|
invalid_params | 400 | Invalid or missing request parameters, headers, or body. |
invalid_client | 400 | The specified client ID is invalid. |
client_not_active | 400 | This client is currently inactive. |
project_not_active | 400 | This project is currently inactive. |
invalid_authorization_code | 400 | The provided authorization code is invalid. |
different_authorize_redirect_uri | 400 | The redirect URI does not match the URI used in the initial authorization request. |
auth_code_already_used | 400 | This authorization code has already been used. |
auth_code_expired | 400 | This authorization code has expired. |
invalid_code_verifier | 400 | The provided code verifier is invalid. |
invalid_refresh_token | 400 | The provided refresh token is invalid. |
refresh_token_expired | 400 | This refresh token has expired. Please sign in again. |
refresh_token_already_used | 400 | This refresh token has already been used. |
invalid_client_credentials | 401 | Invalid client credentials provided. |
system_error | 500 | An unexpected error occurred. Please try again later. |