FILTER BY TAG
Limited Availability

Obtain Merchant Authorization

This section describes how to construct the redirect URL that your application uses to send the merchant to the
Business Center
to grant permissions.
Before your application can send API requests on-behalf-of a merchant, the merchant must grant your application permission to do so. To obtain permission, your application must redirect the merchant to the
Business Center
. The merchant can then log in to their account and review the scope of permissions your application is requesting. After the merchant approves your application to perform the listed permissions,
Cybersource
redirects the merchant to your application. The redirect URL that
Cybersource
uses is determined by the URLs you submitted when registering for OAuth 2.0.
Cybersource
also appends the redirect URL with an authorization code and state status. The authorization codes is necessary to request an access token.
IMPORTANT
Use HTTPS when you redirect merchants to the
Business Center
.
IMPORTANT
The merchant must log in to an account with adequate privileges in order to approve your application's requested permissions. If the merchant is unable to log in when redirected, the merchant must contact
Cybersource
customer support.

Create and Implement a Redirect URL

Follow these steps to construct the URL that your application can use to redirect merchants to the
Business Center
where they can grant permissions.
  1. Set the host domain for the redirect URL:
    • Production:
      https://businesscenter.cybersource.com
      /ebc2/
    • Test:
      https://businesscentertest.cybersource.com
      /ebc2/
  2. Append the host domain with a question mark (
    ?
    ) to designate the start of the query-string.
  3. Include these query-parameters with an ampersand (
    &
    ) after each consecutive parameter. Set the required parameters in the order that they are listed.
    Required Request Parameters
    Request Parameter
    Description
    response_type
    Set to
    code
    .
    client_id
    The client identifier issued by
    Cybersource
    when you registered your application.
    Example:
    client_id=abc123xyz
    redirect_uri
    The URI to which the merchant is redirected to after granting your application authorization in the
    Business Center
    .
    Example:
    redirect_uri=https://app.example.com/callback
    state
    A value your application generates that is used as CSRF protection. The generated value must be unique and cryptographically random. After the merchant grants your application authorization,
    Cybersource
    redirects the merchant to your application and appends this value to the redirect URL.
    Example:
    state=af0ifjsldkj
    code_challenge
    The PKCE code challenge is a SHA-256 hash of the code verifier, encoded using Base64URL. For more information about generating a code verifier and its code challenge value, see the Generating a Code Verifier and Code Challenge section below.
    code_challenge_method
    Set to
    S256
    .
    Example: Readable Redirect URL
    This example is formatted in a readable structure and is not intended to be used.
    https://businesscenter.cybersource.com
    /ebc2/oauth2/authorize? response_type=code& client_id={yourClientId}& code_challenge={codeChallenge}& code_challenge_method=S256& redirect_uri={yourCallbackUrl}& state={state}
    Example: Encoded URL for Implementation
    This example is formatted correctly for implementation.
    https://businesscenter.cybersource.com
    /ebc2/oauth2/authorize?response_type=code&client_id={yourClientId}&code_challenge={codeChallenge}&code_challenge_method=S256&redirect_uri={yourCallbackUrl}&state={state}
  4. Set your application to use your constructed URL to redirect merchants who want to grant permissions.
  5. Cybersource
    redirects the merchant back to your application after the merchant completes granting permissions. The URL used to redirect the merchant to your application is the URL you submitted during registration. It includes these response parameters appended to it:
    your_registered_redirect_URL?code={authorization_code}&state={state}
    Response Parameters
    Response Parameter
    Description
    code
    The authorization code that is used to request access and refresh tokens. It expires ten minutes after being issued. If the code expires, you must request merchant authorization again.
    state
    The CSRF protection value that you sent in the
    state
    parameter. If this value does not match the value you sent, reject the request.

AFTER COMPLETING THE TASK

After receiving an authorization code, you can now request access tokens. For more information, see Request Access and Refresh Token.

Error Response Codes

These are possible error responses you can receive from unsuccessful requests. Use this reference to troubleshoot unsuccessful requests.
Error Response Codes
HTTP Status
Error Code
Description
400
http_message_not_readable
The request body can not be parsed.
400
invalid_request
The request is malformed, contains invalid syntax, or is missing one or more required parameters.
400
invalid_client
Client authentication failed, or the client is not recognized by the authorization server.
400
invalid_grant
The authorization code is invalid, expired, previously used, or does not match the redirect URI or client that initiated the authorization request.
400
invalid_scope
The requested scope is invalid, unknown, malformed, or not permitted for the client.
403
access_denied
The merchant or user denied the authorization request, or the authorization server rejected the request.
403
insufficient_scope
The access token does not include the scope required to access the requested resource.

Generating a Code Verifier and Code Challenge

The
code verifier
is a cryptographically random string that your client generates. It is uses PKCE to securely identify your redirect URL for merchant authorization with redirect URL
Cybersource
uses.
The
code verifier
is a PKCE used to securely link the authorization request to the token request. Its value is a cryptographic random string that your client generates. After creating the code verifier, create a code challenge. A
code challenge
is a SHA-256-hash value of the code verifier, which is encoded using Base64URL. The code challenge is included in the authorization request. When you request access and refresh tokens, you must include the code verifier to confirm your client's identity.
  1. To create a code verifier, run one of these code snippets in a terminal:
    Java Example
    import java.security.SecureRandom; import java.util.Base64; SecureRandom sr = new SecureRandom(); byte[] code = new byte[32]; sr.nextBytes(code); String codeVerifier = Base64.getUrlEncoder() .withoutPadding() .encodeToString(code); // Use codeVerifier as the code verifier parameter value.
    JavaScript Example
    // Dependency: Node.js crypto module const crypto = require('crypto'); function base64URLEncode(buffer) { return buffer.toString('base64') .replace(/\+/g, '-') .replace(/\//g, '_') .replace(/=/g, ''); } const code_verifier = base64URLEncode(crypto.randomBytes(32)); // Use code_verifier as the code verifier parameter value.
  2. Run one of these code snippets and include the code verifier value that you generated in the previous step:
    Java Example
    import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.SecureRandom; import java.util.Base64; SecureRandom sr = new SecureRandom(); byte[] code = new byte[32]; sr.nextBytes(code); String codeVerifier = Base64.getUrlEncoder() .withoutPadding() .encodeToString(code); byte[] bytes = codeVerifier.getBytes(StandardCharsets.US_ASCII); MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] digest = md.digest(bytes); String codeChallenge = Base64.getUrlEncoder() .withoutPadding() .encodeToString(digest); // Use codeChallenge as the code challenge parameter value. // Use "S256" as the code challenge method parameter value.
    JavaScript Example
    const crypto = require('crypto'); function base64URLEncode(buffer) { return buffer.toString('base64') .replace(/\+/g, '-') .replace(/\//g, '_') .replace(/=/g, ''); } function sha256(buffer) { return crypto.createHash('sha256').update(buffer).digest(); } const code_verifier = base64URLEncode(crypto.randomBytes(32)); const code_challenge = base64URLEncode(sha256(code_verifier));
  3. Set the
    code_challenge
    parameter to the generated code challenge value.
  4. Store the original code verifier value temporarily. You must send the same code verifier in your access token request.
    IMPORTANT
    Do not regenerate the code verifier before the token request.