Creating an Access Token Request

Submitting an access token request is pivotal to successfully querying a customer's account information.

The scope of analysis and service supported by the Token SDK includes comparing a customer's (PSUClosedPayment Services User – an individual person or legal business entity making use of an Open Banking service as a payee, payer or both.) accounts and transaction history to a range of financial service options, aggregating data across participating financial institutions and customers to create marketing profiles, and making new transactions and account changes on the PSU's behalf.

Remember, to access Account Details, the value of supports_account_details_api must be true in the Bank object for each bank displayed to the user for selection from the GET /banks payload.

API support for accessing a PSU's account information institutes a communications workflow that ensures all PSD2 mandates for PSU consent and authorisation are met. Pictured next (hover to enlarge) is the general flow.

First, however, you have to build the token request and store it. At a minimum, it must contain the relevant details for the account you wish to access — bank, grantor (the account holder), your memberId, and the type of information (resources) you want to receive about the account — account list, balances, transactions, and/or transfer destinations — along with a description of why you are requesting the information and your callback URL, so you can redeem the token once it's issued. There are also a number of other, optional, data items you can include for your own tracking and control.

A request-id is generated and returned with the token payload in response to your token request submission. This identifier references the stored TokenRequest and is used to validate the conditions of the request and to verify that these conditions remain unchanged. You must include the request-id in the URL that redirects the customer to Token to obtain user authentication and authorisation.

Each token request submission has a time limit of 20 minutes. If you do not receive a response within the allotted timeframe, your token request expires and a new request will have to be created and submitted.

Most importantly, the TPP member creating the TokenRequest must match the TPP member redeeming the token or token redemption will fail and access will be denied.

Building and Storing the Request

All access token requests are created with the selected-language variant of the accessTokenRequestBuilder() method. Once the token request is created, you store it, awaiting a corresponding request-id, which is returned by Token in a response payload. In addition to the request-id, the response payload reflects all the information you included in your original request. Equipped with the request-id, you can redeem the token, thereby receiving the requested information regarding the customer's bank account(s).

Even though it's really quite simple and incredibly secure, accuracy remains paramount vis-à-vis making the right calls with the right information at the right time.

So, let's examine the key field definitions for an access token request call.

Tip: Classes, methods and parameters are initially presented in their default Java syntax. Select the corresponding tab — Java, JavaScript or C# in the navigation bar of the first code example in the sequence — to display the correct syntax and field names for the SDK language chosen.

The key fields comprising an access token request are defined in the following table.

Fields in an Access Token Request
Field Description Required/ Optional
actingAs Party or entity for which the to member is acting as a proxy. See Creating a Token on Behalf of another Party for details on setting the properties for this field. Optional
accountId Identifier of the grantor-selected bank account — the user's bank account — e.g., "Main Checking" Optional
authorizationMetadata Needed to capture additional information from the user for initial authorization by the bank, thereby allowing the user to proceed with providing consent for the initiation request. Maps the key-value pairs from the getBanks() response, where key is the name of the field and value is the value of the field. Required
bankId When specified, indicates you wish to bypass the Token bank selection UI and use your own bank selection UI for the request. See Using the getbanks Method Optional
callBackState TPP-specified string that persists state between request and callback Optional, but recommended
customizationId Identifier for customizing the UI of the Token web app (see Customising the Token Webapp for details) Optional

Description of the information request with the following qualifiers:

•  description in a subsequent call must match description in originating request

•  description omitted in originating request must also be omitted in subsequent calls

•  description omitted in subsequent call will be replaced with refId

This description field maps to description in the bank's consentRequest presented to the user.

Warning: A description mismatch between the originating TPP token request and subsequent token lookups/changes/updates (retrieve, redeem, or cancel) will throw an exception.

grantee "To" TPP member placing the access request, which will receive the information upon successful token redemption Required
grantor "From" Alias (DOMAIN orEMAIL) of the user member granting access to the specified bank account(s). To review the methods for finding an alias see Fetching an Alias. Required
receiptRequested Boolean; requests a receipt be sent to the grantor member's default email address Optional
redirectUrl Specifies the callback URL where your server will initiate token redemption Required

Reference identifier for the token; not to be confused with requestId. RefId maps to tppRefId in the bank's consentRequest. It is needed to match/verify the originating token request with the bank's consent request.

Warning: A description mismatch between the originating token request and subsequent token lookups/changes/updates (retrieve, redeem, or cancel) will throw an exception.

resourceType Specifies the type of information for which access permission is requested:
  • ACCOUNTS – list of accounts with associated names
  • BALANCES – current balance of each requested account
  • TRANSACTIONS – recorded account activity in terms of debits and credits
  • TRANSFER_DESTINATIONS – account number and sort code/BIC, where applicable
  • FUNDS_CONFIRMATIONS – confirmation of available funds in the specified account
  • STANDING_ORDERS – scheduled recurring payments, frequency and duration
token_expiration Sets the expiration date and time for the token request (default is 20 minutes); override of default value is not supported by all banks Optional
traceID TPP-provided unique value captured by Token and sent across to the bank to be stored with the request throughout its lifecycle as an audit-trail aid. Optional

Here's the basic structure of the request.


* Stores an access token request.


* @param grantee – Token member requesting the access token be created

* @return – a token request-id


public static String storeAccessTokenRequest(Member grantee) {

    // Create token request to be stored

    TokenRequest request = TokenRequest.accessTokenRequestBuilder(ACCOUNTS, BALANCES)

        .setToMemberId(grantee.memberId()) // TPP's member ID

        .setRedirectUrl("") // callback URL


            .setValue("") // customer-user alias



        .setBankId("iron") // bank ID

        .setCsrfToken(generateNonce()) // nonce for CSRF check

        // use keys in bank authorization metadata from getBanks() response

        .putAllAuthorizationMetadata(new HashMap<>())



    return grantee.storeTokenRequestBlocking(request);


Nonce generation to protect account information ensures that the specified transfer destination account cannot be reused in a CSRFClosedCross-site request forgery, also known as XSRF, Sea Surf or Session Riding – is an attack vector that tricks a web browser into executing an unwanted action in an application to which a user is logged in. CSRFs are typically conducted using malicious social engineering, such as an email or link that tricks the victim into sending a forged request to a server. As the unsuspecting user is authenticated by their application at the time of the attack, it’s impossible to distinguish a legitimate request from a forged one. Token guards against this type of attack by checking each request against the session ID. replay attack. As desired, you can add to or replace the resource types in the example (in yellow) with TRANSACTIONS and/or TRANSFER_DESTINATIONS.

After storing the transfer token request, you're ready to construct the redirect URL for authorisation so the customer can authenticate, provide consent, and authorise account information access as previously outlined in the AIS communication workflow.

Tip: When integrating the Token SDK with a mobile app, you can initiate the token request in WebViewClosedA browser engine that you can insert like an iframe into your native app and programmatically tell it what web content to load. so that the redirect is also in the form of an HTTP 302ClosedAn HTTP response with this status code will additionally provide a URL in the header field Location. This is an invitation to the user agent (i.e., a web browser) to make a second, otherwise identical, request to the new URL specified in the location field. The end result is a redirection to the new URL.. However, in terms of activity layout, WebView lacks many features found in a fully developed web browser.

Nevertheless, WebView provides increased control over the UI and advanced configuration options that allow you to embed web pages in a specially-designed environment for your app, but you will forfeit an array of features supported by Chrome, Firefox, and other COTSClosedCommercial off-the-shelf – a product designed to be easily installed and to interoperate with existing system components. browsers.