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.

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("https://mytpp.com/callback") // callback URL

        .setFromAlias(Alias.newBuilder()

            .setValue("grantor-alias@token.io") // customer-user alias

            .setType(Alias.Type.EMAIL)

            .build())

        .setBankId("iron") // bank ID

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

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

        .putAllAuthorizationMetadata(newHashMap<>())

        .build();

 

    return grantee.storeTokenRequestBlocking(request);

}

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 Description of the access requested 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: If description in a subsequent token request for lookups/changes/updates (retrieve, redeem, or cancel) doesn't match the description in the originating token request, an exception will be thrown.

Optional
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
refId

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.

Required
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

Required
token_expiration

Sets the consent expiration date and time for access requests (default is 90 days per PSD2ClosedPSD2 stands for Payment Services Directive 2 and is a new EU regulation in effect since September 14, 2019. It governs electronic and other non-cash payments. The main provision of PSD2 is for Strong Customer Authentication (SCA), a process that seeks to make online payments more secure and reduce fraud while increasing authorisation rates. The European Banking Authority (EBA) recently extended the deadline for PSD2 compliance until December 31, 2020. regulation); override of the default value is not supported by all banks. This is a particularly important parameter to pass to CMA9ClosedAs part of the Open Banking initiative, the CMA9 are the nine largest banks in the UK as determined by the Competition and Markets Authority (CMA). The CMA is an independent department of the UK government chartered to promote market competition and fairness, and reduce any harmful monopolies. banks to ensure an adequate custom consent expiry period is set for the access token upon successful authorisation.

JSON in a successful response payload will look something like this:

{"Data:["Permissions":["ReadAccountsDetails","ReadBalances"], "ExpirationsDateTime":"2020-10-21T18:03:07.371+01:00"}, "Risk":{}}

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

Caution: A PANClosedPrimary Account Number – refers to a 14-, 15-, 16-, or even up to 19-digit number generated as a unique identifier designated for a primary account; also called payment card number and permanent card number. is disallowed in the token request payload within the refId and description fields. In accordance with the PA-DSSClosedPayment Application Data Security Standard – Council-managed program formerly under the supervision of the Visa Inc. program known as the Payment Application Best Practices (PABP). The goal of PA-DSS is to help software vendors and others develop secure payment applications that do not store prohibited data, such as full magnetic stripe, CVV2 or PIN data, and ensure their payment applications support compliance with the PCI DSS. Payment applications that are sold, distributed or licensed to third parties are subject to the PA-DSS requirements. In-house payment applications developed by merchants or service providers that are not sold to a third party are not subject to the PA-DSS requirements, but must still be secured in accordance with the PCI DSS. security standard, RegexClosedAPI to define a pattern for searching or manipulating strings. is used for pattern matching of numeric strings that intentionally or inadvertently reveal or resemble a PAN in the refId or description of a token request. Potential PAN patterns found will now throw an exception.

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.

Important Update: In the access token response payload, account_identifiers are now specified in AccountDetails, which include bic and account_holder_name. These fields were recently added pursuant to deprecating the resolveTransferDestinations call by TPPs. Previously, TPPs could obtain these data — account identifiers, BICClosedBank Identifier Code – a unique identifier for a specific financial institution. A BIC is composed of a 4-character bank code, a 2-character country code, a 2-character location code and an optional 3-character branch code., and customer name — after a getAccount or getAccountDetails call with a subsequent resolveTransferDestinations call, wherein the debit-side bank returned its preferred transfer method(s) — SEPAClosedSingle Euro Payments Area – a payments system created by the European Union (EU) which harmonizes the way cashless payments transact between euro countries. European consumers, businesses, and government agents who make payments by direct debit, instant credit transfer, and through credit transfers use the SEPA architecture. The single euro payment area is approved and regulated by the European Commission. SEPA currently includes 36 members. It encompasses the 28 EU member states along with Iceland, Norway, Liechtenstein, Switzerland, Andorra, Vatican City, Monaco and San Marino. The single euro payment area remains an ongoing, collaborative process between these parties. SEPA is in the process of harmonizing rules regarding mobile and online payments., FPSClosedFaster Payments Service – UK banking initiative to reduce payment times between different banks' customer accounts from the three working days that transfers take using the long-established BACS system to typically a few seconds., DomesticClosedBanks make domestic wire transfers (as opposed to international wire transfers) to send funds to financial institutions residing in the same country or financial zone., etc. — along with the bic and CustomerData.

However, to optimise API utilisation and eliminate the additional call to resolveTransferDestinations, banks are now required to populate account_identifiers, bic and account_holder_name in the AccountDetails object returned by the getAccount and getAccountDetails calls. TPPs are therefore encouraged to discontinue relying on the resolveTranserDestinations method.

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.