• None
  • Manage Credentials
Launch IDE ↗

Stitch SSO

5.7. Client Tokens

What are client tokens?

Most of the functionality of the Stitch API is protected by what is known as user tokens. User tokens represent a client's authorization to access certain features of the user's bank account.

In contrast, a client token is issued to a client by the API and represents the time limited ability to access certain features of the client's profile on the API.

A client token is issued when the client sends a client assertion to the token endpoint. To generate a client assertion, a confidential client is required.

Client Scopes

Scopes can be thought of as permissions to access certain features of the API.

If you attempt to make a request that needs extra scopes, the API response will return an error that lists the extra scopes required. The API documentation embedded in the IDE also includes the required scopes for different fields and mutations.

Client tokens have a different set of scopes than user tokens. The following scopes are currently available:

Client Scopes
client_paymentrequestThe scope is required to create, view and manage payment requests.
client_bankaccountverificationThe scope is required to submit bank account verification requests.
client_imageuploadThis scope allows you to use the clientImageUpload endpoint
client_businesslookupThis scope allows you to lookup a business by name, registration number, or director identity / passport numbers.

In the next sections, we'll go through the steps needed to retrieve a client token with the client_paymentrequest scope.

Client Tokens

To proceed, you'll need a Client Id and Certificate. Stitch has sample test clients available that can access a simulated payment environment.

You'll also have needed to have generated a private_key_jwt from the certificate by following the steps in the confidential client guide.

Stitch uses the OAuth 2.0 Client Credentials Flow for client tokens. This flow entails making a POST request to the endpoint with the following body parameters. The parameters are form encoded per OAuth 2.0 standards.

Token Request Body Parameters
client_idThis is a unique ID issued to you by a Stitch engineer

A space separated list of requested scopes.

grant_typeShould be the value client_credentials for this flow
audienceShould always be the value
client_assertion_typeShould always have the value urn:ietf:params:oauth:client-assertion-type:jwt-bearer
client_assertionThe value of the generated private_key_jwt

Retrieving the Token Using cURL

This example bash script uses cURL to retrieve the access and refresh token.

You'll need to replace the clientId, clientSecret, and scopes with the appropriate values. This request if correctly formed, will return a JSON payload with the token.

5curl --location --request POST '' \
6--header 'Content-Type: application/x-www-form-urlencoded' \
7--data-urlencode 'grant_type=client_credentials' \
8--data-urlencode "client_id=$clientId" \
9--data-urlencode 'client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer' \
10--data-urlencode 'audience=' \
11--data-urlencode "scope=$scopes" \
12--data-urlencode "client_assertion=$clientAssertion"

Retrieving the Token Using JavaScript and the Fetch API

1async function retrieveTokenUsingAuthorizationCode(clientId, clientSecret, scopes) {
2 const body = {
3 grant_type: 'client_credentials',
4 client_id: clientId,
5 client_secret: clientSecret,
6 scope: scopes.join(' '),
7 audience: ''
8 };
10 const bodyString = Object.entries(body).map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join('&');
12 const response = await fetch('', {
13 method: 'post',
14 headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
15 body: bodyString,
16 });
18 const responseBody = await response.json();
19 console.log('Tokens: ', responseBody);
20 return responseBody;

Retrieving the Token Using Postman

Download the following Postman collection, and import it into Postman:


The first request in the collection is "Retrieve Client Token". Replace the entries in the Body tab with the appropriate values, and click send. The request if correctly formed will return a JSON payload with the token.

Response Body

A typical response body returned from the token endpoint will look like the following:

2 "access_token": "udfc_WxDqxwfs5IKNHYohqGDZ9vwmyENvQYN7_cjW6M",
3 "expires_in": 3600,
4 "token_type": "Bearer",
5 "scope": "client_paymentrequest"
Token Response Body Parameters
access_tokenThe token needed to query the Stitch API
expires_inThe number of seconds until the token expires
scopeThe scopes that were granted by the user

We recommend that tokens are cached and only refreshed once expired as token generation is a cryptographically intensive process and so can slow down queries if retrieved on every request.

Using the confidential client to make API requests

Once you have obtained a token, you can use it to query the API in the same way that user tokens can. The short version is that you will need to include the token as the value in the Authorization header, prefixed with the string "Bearer ".

The Making API calls with the Access Token section of the SSO Intro goes into more detail.