Integration steps
- Register your client
- Request access
- Get your access and refresh tokens
- Use your access token
- Refresh your access token
Requirements
To integrate with Adyen’s OAuth service, you need to have:-
An account with the OAuth apps manage user role.
- On our test environment, merchant accounts created since November 2023 have this role enabled by default. If your account was created before, reach out to support.
- On our live environment, only partner accounts have the OAuth apps manage role.
Step 1: Register your client
An OAuth client is your application or website which accesses your customer’s account resources on their behalf. To register your OAuth client:- Log in to your Partner Portal.
- Go to Developer > OAuth apps.
- Select Create OAuth app.
- Enter your application name, URL, and description and select Continue.
- Enter your Redirect URL, select the scope of access and select Continue.
- After your customer authorizes your application, we redirect them to your Redirect URL.
- Copy the Client secret and store it securely. We do not store this value for you to access later.
Step 2: Request access
Step 2.1: Construct the access grant URL
To request access to your customer’s account resources, you need to redirect them to an Adyen page where they authenticate and grant you access. Create the URL that points to this location, using the following reference:Code challenge
During the OAuth flow, we use Proof Key for Code Exchange (PKCE) to add a layer of security on top of the client secret. PKCE works as follows:- For every access request, you create and supply a unique
code_challenge, also known as a PKCE secret. - When you exchange the authorization code for the access token, you supply the associated
code_verifier.
-
To create your
code_verifier, generate a random string with the following properties:- The string has a minimum length of 43 characters and a maximum length of 128 characters.
- Allowed characters are [A-Z] / [a-z] / [0-9] / ”-” / ”.” / ”_” / ”~”.
-
To create your
code_challenge, create a base64url-encoded SHA256 hash of thecode_verifier.
Example
- To create your
code_verifier, generate a random URL-safe string:dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk. - To create your
code_challenge, base64 URL-encode the SHA256 hash of thecode_verifier:E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM.
Handle the redirect
Whether the authorization was successful or failed, your customer is redirected to yourredirect_uri.
Successful authorization
After successful authorization, your customer is redirected to:
In the next step, you will use the CODE to request access and refresh tokens.
Failed authorization
After failed authorization, your customer is redirected to:Step 2.2: Redirect your customer
Add a button labeled Connect with Adyen to your application for your customers to initiate the access delegation. When your customer clicks the button, redirect them to the URL you constructed in the previous step, which points to an Adyen login screen where your customer authenticates and authorizes your request.Step 3: Get your access and refresh tokens
Make a POST request to the/token endpoint to exchange your authorization code for:
- A short-lived (24 hours by default) access token, to make API requests on behalf of your customer.
- A one-time-use refresh token, to get a new access token after your previous expired.
POST request to:
x-www-form-urlencoded.
Handle the response
The response body depends on whether your request was successful or unsuccessful.Successful response
Unsuccessful response
Step 4: Use your access token
Authorize API requests with your access token as bearer token:Step 5: Refresh your access token
Your access token is valid until the expiry period has elapsed. Find the expiry period in the response of the/token request.
Your refresh token expires only upon its usage. A short grace period is provided to allow for retries in the event of network errors or similar issues.
To get a new access token, make an HTTP POST request to:
x-www-form-urlencoded.
When you successfully refresh your access token:
- Your previous
access_tokenimmediately expires. This ensures there is no more than one validaccess_tokenper authorization at a given point in time. - Your previous
refresh_tokenexpires shortly. This lets you retry the operation if the response was lost, for example during network issues.
Successful response
The scope of access and merchant accounts that the
access_token provides access to remains unchanged from when you got your access and refresh tokens.
Unsuccessful response
Go live
When you are ready to go live, make sure to:- Register an OAuth client in your live Partner Portal.
- Change all instances of the OAuth client ID, client secret, and client URI to reflect the OAuth client in your live account.
- Change all API endpoints from test to live.
