Plaid logo
Docs
ALL DOCS

Auth

  • Introduction to Auth
  • Add Auth to your app
  • Move money with our partners
  • Add institution coverage
Plaid logo
Docs
Plaid.com
Get API keys
Open nav

Add Auth to your app

Use Auth to connect user bank accounts

In this guide, we'll start from scratch and walk through how to use Auth to connect to your users' bank accounts and obtain the information needed to set up funds transfers. If you are already familiar with using Plaid and are set up to make calls to the Plaid API, you can skip ahead to Fetching auth data.

Note that these instructions are intended for using Auth without a Plaid partner. If you will be using a Plaid partner such as Stripe or Dwolla to process payments, see Auth payment partners to find the specific instructions for your payment processor.

Get Plaid API keys and complete application and company profile

If you don't already have one, you'll need to create a Plaid developer account. After creating your account, you can find your API keys under the Team Settings menu on the Plaid Dashboard.

You will also need to complete your application profile and company profile in the Dashboard. The information in your profile will be shared with users of your application when they manage their connection on the Plaid Portal. Your application profile and company profile must be completed before connecting to certain institutions in Production.

Install Plaid libraries

You can use our official libraries to connect to the Plaid API from your application:

Select group for content switcher
Select Language
Copy
1# Install via npm
2npm install --save plaid

Create an Item in Link

Plaid Link is a drop-in module that provides a secure, elegant authentication flow for each institution that Plaid supports. Link makes it secure and easy for users to connect their bank accounts to Plaid. Note that these instructions cover Link on the web. For instructions on using Link within mobile apps, see the Link documentation.

Using Link, we will create a Plaid Item, which is a Plaid term for a login at a financial institution. An Item is not the same as a financial institution account, although every account will be associated with an Item. For example, if a user has one login at their bank that allows them to access both their checking account and their savings account, a single Item would be associated with both of those accounts. If you want to customize Link's look and feel, you can do so from the Dashboard.

When using Auth, you will typically only need access to the specific account that the end user wants to use to fund the payment, rather than all accounts they may have at the same institution. Because of this, it is recommended to use the Account Select Link customization when configuring Link for use with Auth, to limit unnecessary access to user accounts. You can enable Account Select from the Dashboard](https://dashboard.plaid.com/link).

Before initializing Link, you will need to create a new link_token on the server side of your application. A link_token is a short-lived, one-time use token that is used to authenticate your app with Link. You can create one using the /link/token/create endpoint. Then, on the client side of your application, you'll need to initialize Link with the link_token that you just created.

In the code samples below, you will need to replace PLAID_CLIENT_ID and PLAID_SECRET with your own keys, which you can obtain from the Dashboard.

Create a link_token
Select group for content switcher
Select Language
Copy
1// Using Express
2const express = require('express');
3const app = express();
4app.use(express.json());
5
6const { Configuration, PlaidApi, PlaidEnvironments } = require('plaid');
7
8const configuration = new Configuration({
9 basePath: PlaidEnvironments[process.env.PLAID_ENV],
10 baseOptions: {
11 headers: {
12 'PLAID-CLIENT-ID': process.env.PLAID_CLIENT_ID,
13 'PLAID-SECRET': process.env.PLAID_SECRET,
14 },
15 },
16});
17
18const client = new PlaidApi(configuration);
19
20app.post('/api/create_link_token', async function (request, response) {
21 // Get the client_user_id by searching for the current user
22 const user = await User.find(...);
23 const clientUserId = user.id;
24 const request = {
25 user: {
26 // This should correspond to a unique id for the current user.
27 client_user_id: clientUserId,
28 },
29 client_name: 'Plaid Test App',
30 products: ['auth'],
31 language: 'en',
32 webhook: 'https://webhook.example.com',
33 redirect_uri: 'https://domainname.com/oauth-page.html',
34 country_codes: ['US'],
35 };
36 try {
37 const createTokenResponse = await client.linkTokenCreate(request);
38 response.json(createTokenResponse.data);
39 } catch (error) {
40 // handle error
41 }
42});
Install Link dependency
Select Language
Copy
1<head>
2 <title>Connect a bank</title>
3 <script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>
4</head>
Configure the client-side Link handler
Copy
1const linkHandler = Plaid.create({
2 token: (await $.post('/create_link_token')).link_token,
3 onSuccess: (public_token, metadata) => {
4 // Send the public_token to your app server.
5 $.post('/exchange_public_token', {
6 public_token: public_token,
7 });
8 },
9 onExit: (err, metadata) => {
10 // Optionally capture when your user exited the Link flow.
11 // Storing this information can be helpful for support.
12 },
13 onEvent: (eventName, metadata) => {
14 // Optionally capture Link flow events, streamed through
15 // this callback as your users connect an Item to Plaid.
16 },
17});
18
19linkHandler.open();

Get a persistent access_token

Next, on the server side, we need to exchange our public_token for an access_token and item_id. The access_token will allow us to make authenticated calls to the Plaid API. Doing so is as easy as calling the /item/public_token/exchange endpoint from our server-side handler. We'll use the client library we configured earlier to make the API call.

Save the access_token and item_id in a secure datastore, as they’re used to access Item data and identify webhooks, respectively. The access_token will remain valid unless you actively chose to expire it via rotation or remove the corresponding Item via /item/remove. The access_token should be stored securely, and never in client-side code. A public_token is a one-time use token with a lifetime of 30 minutes, so there is no need to store it.

Select group for content switcher
Select Language
Copy
1// Using Express
2const express = require('express');
3const app = express();
4app.use(express.json());
5
6const { Configuration, PlaidApi, PlaidEnvironments } = require('plaid');
7
8const configuration = new Configuration({
9 basePath: PlaidEnvironments[process.env.PLAID_ENV],
10 baseOptions: {
11 headers: {
12 'PLAID-CLIENT-ID': process.env.PLAID_CLIENT_ID,
13 'PLAID-SECRET': process.env.PLAID_SECRET,
14 'Plaid-Version': '2020-09-14',
15 },
16 },
17});
18
19const client = new PlaidApi(configuration);
20
21app.post('/api/exchange_public_token', async function (
22 request,
23 response,
24 next,
25) {
26 const publicToken = request.body.public_token;
27 try {
28 const response = await client.itemPublicTokenExchange({
29 public_token: publicToken,
30 });
31 const accessToken = response.data.access_token;
32 const itemID = response.data.item_id;
33 } catch (error) {
34 // handle error
35 }
36});

Fetching Auth data

Now that the authentication step is out of the way, we can begin using authenticated endpoints from the Plaid API. Once you've retrieved the numbers for an account, you can supply them to your payments system to set up funds transfers. For more detailed information on the schema, see /auth/get.

Select group for content switcher
Select Language
Copy
1const { AuthGetRequest } = require('plaid');
2
3// Use Auth and pull account numbers for an Item
4const request: AuthGetRequest = {
5 access_token: testAccessToken as string,
6};
7try {
8 const response = await plaidClient.authGet(request);
9 const accountData = response.data.accounts;
10 if (response.data.numbers.ach.length > 0) {
11 // Handle ACH numbers (US accounts)
12 const achNumbers = response.data.numbers.ach;
13 }
14 if (response.data.numbers.eft.length > 0) {
15 // Handle EFT numbers (Canadian accounts)
16 const eftNumbers = response.data.numbers.eft;
17 }
18 if (response.data.numbers.international.length > 0) {
19 // Handle International numbers
20 const internationalNumbers = response.data.numbers.international;
21 }
22 if (response.data.numbers.bacs.length > 0) {
23 // Handle BACS numbers (British accounts)
24 const bacsNumbers = response.data.numbers.bacs;
25 }
26} catch (error) {
27 //handle error
28}

Example response data is below. Note that this is test account data; real accounts would not have all four sets of numbers.

Copy
1{
2 "accounts": [
3 {
4 "account_id": "vzeNDwK7KQIm4yEog683uElbp9GRLEFXGK98D",
5 "balances": {
6 "available": 100,
7 "current": 110,
8 "limit": null,
9 "iso_currency_code": "USD",
10 "unofficial_currency_code": null
11 },
12 "mask": "9606",
13 "name": "Plaid Checking",
14 "official_name": "Plaid Gold Checking",
15 "subtype": "checking",
16 "type": "depository"
17 }
18 ],
19 "numbers": {
20 "ach": [
21 {
22 "account": "9900009606",
23 "account_id": "vzeNDwK7KQIm4yEog683uElbp9GRLEFXGK98D",
24 "routing": "011401533",
25 "wire_routing": "021000021"
26 }
27 ],
28 "eft": [
29 {
30 "account": "111122223333",
31 "account_id": "vzeNDwK7KQIm4yEog683uElbp9GRLEFXGK98D",
32 "institution": "021",
33 "branch": "01140"
34 }
35 ],
36 "international": [
37 {
38 "account_id": "vzeNDwK7KQIm4yEog683uElbp9GRLEFXGK98D",
39 "bic": "NWBKGB21",
40 "iban": "GB29NWBK60161331926819"
41 }
42 ],
43 "bacs": [
44 {
45 "account": "31926819",
46 "account_id": "vzeNDwK7KQIm4yEog683uElbp9GRLEFXGK98D",
47 "sort_code": "601613"
48 }
49 ]
50 },
51 "item": {
52 "available_products": [
53 "balance",
54 "identity",
55 "payment_initiation",
56 "transactions"
57 ],
58 "billed_products": ["assets", "auth"],
59 "consent_expiration_time": null,
60 "error": null,
61 "institution_id": "ins_117650",
62 "item_id": "DWVAAPWq4RHGlEaNyGKRTAnPLaEmo8Cvq7na6",
63 "webhook": "https://www.genericwebhookurl.com/webhook"
64 },
65 "request_id": "m8MDnv9okwxFNBV"
66}

Tutorial and example code in Plaid Pattern

For a real-life example of an app that incorporates Auth, see the Node-based Plaid Pattern Account Funding sample app. Pattern Account Funding is a sample account funding app that fetches Auth data in order to set up funds transfers. The Auth code can be found in items.js.

For a tutorial walkthrough of creating a similar app, see Account funding tutorial.

Next steps

Once Auth is implemented in your app, see Full Auth coverage to make sure your app is supporting the maximum number of institutions (US only).

Was this helpful?
Developer community
Github logo
Github logo
StackOverflow logo
StackOverflow logo
Twitter logo
Twitter logo