Skip to content
Vedad Kirlić edited this page Dec 30, 2021 · 3 revisions

Exchanging for an access token

We can use this endpoint to retrieve a new access token. There are two scenarios when this can be used:

  1. Once you've got an authorization code, you can exchange it for an access token.
  2. An access token has expired and you have a refresh token to get a new one.

POST /v1.6/oauth/token

Request Header

Parameter Required Description Type
Accept Yes The content types, expressed as MIME types, the client is able to understand. Use application/json. string
Authorization Yes Authentication type. Use Bearer and a JWT token. The JWT should be a string in the format xxxxx.yyyyy.zzzzz. Learn more about JWT creation. string
Content-Type Yes Indicate the media type of the resource. Use application/json. string

The payload for the Authorization JWT when exchanging an authorization code for an access token:

{
  "client_id": <appId_contractId>,
  "code": <authorization_code>,
  "code_verifier": <code_verifier>,
  "grant_type": "authorization_code",
  "nonce": <^[a-zA-Z0-9]{32}$>,
  "redirect_uri": <registered_redirect_uri>,
  "timestamp": <current_unix_time>
}
Property Required Description Data type
client_id Yes A string consisting of the application ID and contract ID separated by an underscore. ie appId_contractId string
code Yes Authorization code. string
code_verifier Yes The code verifier that was created in the preauthorization process. string
grant_type Yes Pass authorization_code if you're exchanging a code for an access token. string
nonce Yes A 32-char string made up of random alphanumeric characters. string
redirect_uri Yes The redirect URL that's been registered to your digi.me contract. string
timestamp Yes Unix timestamp in seconds. number

The payload for the Authorization JWT when exchanging a refresh token for an access token:

{
  "client_id": <appId_contractId>,
  "grant_type": "refresh_token",
  "nonce": <^[a-zA-Z0-9]{32}$>,
  "redirect_uri": <registered_redirect_uri>,
  "refresh_token": <refresh_token>,
  "timestamp": <current_unix_time>
}
Property Required Description Data type
client_id Yes A string consisting of the application ID and contract ID separated by an underscore. ie appId_contractId string
grant_type Yes Pass refresh_token if you're using a refresh token to retrieve a new access token. string
nonce Yes A 32-char string made up of random alphanumeric characters. string
redirect_uri Yes The redirect URL that's been registered to your digi.me contract. string
refresh_token Yes The refresh token. string
timestamp Yes Unix timestamp in seconds. number

Sample Request API

curl -i -X POST \
   -H "Content-Type:application/json" \
   -H "Accept:application/json" \
   -H "Auth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eiDIIzxEtFrgQwS9DDiRZclFzpiWS-JR7qIRCO0IgHef2gR4ZhIyvcnypdEF4Z3vCnaII4oXHr0IkQ0WgFYe9dFM_FkSwgBnmDApTIuST2HnpyWSPRPV3O8Zih8XjmA8amLf5tJ3WSseNEueCf167bkcFJ0CgGwU3zLCnuwm76TM6yWrD7B5Psx6EcIVsthWSu6DL34rFIRXdn9p_oDEiZDT73R6Yloi62gDd_Etnocsn6jjyQR9yk3jFQyFor5e_vnYTH3q4FX3beVgIw"
}

Response

The string in the token field is JWT and it has the following structure.

{
  "header": {
    "alg": "PS512",
    "jku": <JSON_Web_Key_Set_URL>,
    "kid": <key_identifier>,
    "typ": "JWT"
  },
  "payload": {
     {
        access_token: {
          expires_on: <value>,
          value: <access_token>
      },
      consentid: <consent_id>,
      identifier: {
        id: <id>
      },
      refresh_token: {
        expires_on: <value>,
        value: <refresh_token>
      },
      token_type: 'Bearer'
    }
  },
  "signature": <signed_with_services_private_key>
}

Response Definitions

Response item Description Data type
access_token The access token that can be used to request user data. object
refresh_token A refresh token that can be used to retrieve a new access token once the current one expires. object
token_type Bearer string
consentid Consent ID, ie hashSha512(app_id + contract_id + user_id) string
identifier Default app user scope, ie hashSha512(user_id + app_id) object

Response Errors

Subject to Application, Contract, General and OAuth related errors.

Clone this wiki locally