Skip to content
Exchange Credentials

Exchange Credentials

Exchange credentials for an access token using one of the supported OAuth2 grant types.

Endpoint

/api/v1/tokens

Method

POST

Headers

HeaderRequiredDescription
Content-TypeYesapplication/x-www-form-urlencoded
AuthorizationConditionalRequired for client_credentials grant. Must be a Base64-encoded Basic auth header: Basic base64(client_id:client_secret)

Request Body

FieldTypeRequiredDescription
grant_typestringYesOne of: authorization_code, refresh_token, client_credentials
client_idstringConditionalRequired when grant_type is authorization_code or refresh_token
authorization_codestringConditionalRequired when grant_type is authorization_code
redirect_uristringConditionalRequired when grant_type is authorization_code
code_verifierstringConditionalRequired when grant_type is authorization_code (PKCE)
refresh_tokenstringConditionalRequired when grant_type is refresh_token
statestringNoOptional 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

CodeHTTP StatusDescription
invalid_params400Invalid or missing request parameters, headers, or body.
invalid_client400The specified client ID is invalid.
client_not_active400This client is currently inactive.
project_not_active400This project is currently inactive.
invalid_authorization_code400The provided authorization code is invalid.
different_authorize_redirect_uri400The redirect URI does not match the URI used in the initial authorization request.
auth_code_already_used400This authorization code has already been used.
auth_code_expired400This authorization code has expired.
invalid_code_verifier400The provided code verifier is invalid.
invalid_refresh_token400The provided refresh token is invalid.
refresh_token_expired400This refresh token has expired. Please sign in again.
refresh_token_already_used400This refresh token has already been used.
invalid_client_credentials401Invalid client credentials provided.
system_error500An unexpected error occurred. Please try again later.