[POST] Обмен кода на токен доступа

Endpoint: https://{instance}/oauth2/token

Метод: POST

Описание: обменивает код авторизации на токен доступа и обновленный токен.

grant_type
required
Должен быть authorization_code.
code
required
Код авторизации, полученный на предыдущем шаге.
redirect_uri
required
URI для перенаправления после успешной авторизации. Тот же URI, что и при запросе авторизации.
client_id
required
Идентификатор клиентского приложения.
client_secret
required
Секретный ключ клиентского приложения.
{
  "access_token": "eyJhbGciOiJSUzI1NiIsInR5....", 
  "refresh_token": "8xLnxhdkouixdokzxxcnzxlk...",
  "expires_in": 3600,
  "token_type": "Bearer"
}
access_token
Токен доступа для аутентификации при запросах к API.
refresh_token
Обновленный токен для получения нового access_token после истечения срока действия.
expires_in
Время жизни токена доступа в секундах.
token_type
Тип токена.

В ответе придет ошибка 400 следующего вида:

{
    "error": "invalid_request",
    "error_description": "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.",
    "hint": "Authorization code has expired",
    "message": "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed."
}

Решение: с помощью запроса авторизации повторно получить новый code и передать в теле запроса обмена кода на токен доступа.

В ответе придет ошибка 400 следующего вида:

{
    "error": "invalid_request",
    "error_description": "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.",
    "hint": "Check the `code` parameter",
    "message": "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed."
}

Решение: убедитесь, что в теле запроса заполнено значение параметра code, заполните значением, полученным в запросе авторизации.

В ответе придет ошибка 400 следующего вида:

{
    "error": "invalid_request",
    "error_description": "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.",
    "hint": "Cannot decrypt the authorization code",
    "message": "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed."
}

Решение: убедитесь, что в теле запроса верно заполнено значение параметра code, заполните значением, полученным в запросе авторизации.

В ответе придет ошибка 400 следующего вида:

{
    "error": "invalid_request",
    "error_description": "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.",
    "hint": "Authorization code has been revoked",
    "message": "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed."
}

Решение: с помощью запроса авторизации повторно получить новый code и передать в теле запроса обмена кода на токен доступа.

В ответе придет ошибка 401 следующего вида:

{
    "error": "invalid_request",
    "error_description": "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.",
    "hint": "Check the `client_id` parameter",
    "message": "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed."
}

В ответе придет ошибка 400 следующего вида:

{
    "error": "invalid_client",
    "error_description": "Client authentication failed",
    "message": "Client authentication failed"
}

Решение: убедитесь, что в теле запроса верно заполнены значения параметров client_id / client_secret, полученные у команды разработки Softline ID.