On This Page
Limited AvailabilityHTTPS
Request Access and Refresh Token
Use the authorization code received in Step 2 to request an access token and a refresh token.
Your OAuth application uses the access token to send API requests on behalf of the
merchant. The access token is valid for fifteen minutes. When it expires, your
application uses the refresh token to request a new access token as often as needed. If
the refresh token expires, you must obtain merchant authorization again. A refresh token
is valid for thirty days.
IMPORTANT
Always use HTTPS to securely send and exchange tokens.
Endpoints
Production:
POST
https://api.cybersource.com
/ebc2/oauth2/authorizeTest:
POST
https://apitest.cybersource.com
/ebc2/oauth2/authorizeRequired Request Body Parameters
Body Parameter | Description |
|---|---|
grant_type | Set to authorization_code . |
code | The authorization code received from the authorization
response. For more information about how to obtain an authorization code,
see Obtain Merchant Authorization. |
redirect_uri | The redirect URI that is registered to the OAuth
application. |
client_id | The client ID that is issued during OAuth registration for your
application. |
client_secret | The client secret that is issued during OAuth registration for
your application. |
code_verifier | The code verifier that was created during the authorization
request. It is a PKCE verifier. For more information about how to
create a code verifier, see the Generate a Code Verifier section
in Obtain Merchant Authorization. |
Example: Request an Access Token
Request
POSThttps://api.cybersource.com/oauth2/v4/token Content-Type: application/x-www-form-urlencoded grant_type=authorization_code &code={authorization_code} &redirect_uri={redirect_uri} &client_id={client_id} &client_secret={client_secret} &code_verifier={code_verifier}
Response to a Successful Request
{ "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp...", "token_type": "bearer", "refresh_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...", "expires_in": 900, "refresh_token_expires_in": 2592000, "client_status": "active" }
Response Body Fields
A successful response consists of these body fields and values:
Field | Description |
|---|---|
access_token | The access token that is used to authenticate API requests. You must
include this in the Authorization request header
as the bearer token. |
client_status | The status of the client, such as active . |
expires_in | The amount of time the access token is valid in seconds from the time
the token is created. |
refresh_token_expires_in | The amount of time the refresh token is valid in seconds from the
time the token is created. |
refresh_token | The refresh token that is used to maintain access when the initial
access token expires. |
token_type | The type of token that is issued. |
Error Response Codes
These are possible error responses you can receive from unsuccessful requests. Use
this reference to troubleshoot unsuccessful requests.
HTTP Status | Error Code | Description |
|---|---|---|
400 Bad Request | invalid_request | The request is missing a required parameter, includes an unsupported
parameter value, repeats a parameter, or is otherwise malformed. |
400 Bad Request | invalid_client | Client authentication failed—the client_id is unknown,
or the client credentials are missing or malformed. |
400 Bad Request | invalid_grant | The supplied authorization grant or refresh token is invalid, expired,
revoked, or does not match the redirect URI used in the authorization
request. |
400 Bad Request | invalid_scope | The requested scope is unknown, malformed, or exceeds the scope granted
to the client. |
400 Bad Request | http_message_not_readable | The request body could not be parsed, typically because of malformed JSON
or an incorrect Content-Type header. |
401 Unauthorized | — | Client authentication failed. |
500 Internal Server Error | — | An unexpected error occurred while processing the request. |