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.id/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.id/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.id/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_params400Missing or invalid request params, headers, or body
invalid_client400The client ID is invalid
client_not_active400The client is not active
project_not_active400The project is not active
invalid_authorization_code400The authorization code is invalid
different_authorize_redirect_uri400The redirect URI does not match the one used in the authorization request
auth_code_already_used400The authorization code has already been used
auth_code_expired400The authorization code has expired
invalid_code_verifier400The PKCE code verifier does not match
invalid_refresh_token400The refresh token is invalid
refresh_token_expired400The refresh token has expired
refresh_token_already_used400The refresh token has already been used
invalid_client_credentials401Client ID or secret is invalid
system_error500Internal server error