Token endpoint

Endpoint URL: POST /oauth2/token

Endpoint is used for exchanging authorization code for access token.

Request

Example request for token
$ curl --location --request POST 'https://connect.okonto.pl/oauth2/token' \
--header 'Authorization: Basic d3d3LmV4YW1wbGUuY29tLmZyb250Lm9uZXRhcGkucGw6ZzlhbHNzZGUwZmx0cDA1ZHM3ZW0' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'code=11fcb623bd60dc516693e44c9da9efc6ffb2debc0add36ec6d510d9f7522b506cs' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'redirect_uri=http://www.example.com/callback'

Parameters:

  • code - value you received from authorization endpoint

Headers:

  • Content-Type - should be set to application/x-www-form-urlencoded and parameters should be send in this format

  • Authorization - authorization header should be provided in Basic auth scheme

For building this Authorization header you will have to use client_id and client_secret received when registering client.

Example of building Authorization header using Python
import base64

client_id = 'www.example.com.front.onetapi.pl'
client_secret = 'g9alssde0fltp05ds7em'
token = base64.b64encode((client_id + ':' + client_secret).encode()).decode()
headers['Authorization'] = 'Basic ' + token

Response

Example response for getting token request
{
    "access_token": "047b0a8339c7fb9f623d3e2e8ae69c2z3eh5r4df1501pa34cba8439f7d0c2c1fcs",
    "token_type": "bearer",
    "expires_in": 36000,
    "refresh_token": "3786016856301de8f1e7b47036op24df820e683863e2908fb7544ceb9737f1d8cs"
}

Errors handling

  • 400 BAD REQUEST - for all client side errors like: lack of authorization code, wrong authorization code, invalid credentials in Authorization header.

  • 503 SERVICE UNAVAILABLE - for problems encountered on the server side.