Quickstart: Add Nango to your app
Just want to see Nango in Action? Check out our 1min demo video
Follow these 4 steps to run OAuth flows with Nango in your app in 15 minutes.
Step 1: Get your Nango instance ready​
The easiest and fastest way to get a production ready Nango instance is with Nango Cloud.
- Nango Cloud
- Localhost
- Self-hosted
git clone https://github.com/NangoHQ/nango-quickstart.git && cd nango-quickstart
docker compose up # Keep the tab open
Once Nango is running locally, open the dashboard in your browser.
You can self-host Nango on a single machine with our docker images. Check the Nango Self Hosted page for a list of all providers, or use these 1-click deploy options:
Once Nango is running on your instance, open the dashboard at https://<INSTANCE-URL>:3003
.
Step 2: Configure your API/Integration​
Click the "Add New" button on the dashboard's Integrations
page, it will ask for you for 4 things:
Find your Provider/API in the dropdown.
Decide what this config should be called in Nango, we call this the
<CONFIG-KEY>
here and the UI calls it the "Unique Key". Most people pick the same name as the API, e.g.github
.Create an OAuth app on your Provider's developer portal. Obtain the client id & client secret (sometimes also called app id and app secret or similar) and add them.
You should also get a list of scopes you want to request. Prepare them in a comma separated list:
scope1,scope2,scope3
(no matter what the provider tells you, Nango will reformat them) and add them to the Scopes field.
Click "Save" and you are ready to trigger your first OAuth flow!
Step 3: Trigger the OAuth flow from the frontend​
To trigger an OAuth flow in your frontend use our frontend SDK.
- Nango Cloud
- Localhost
- Self-hosted
You will need the Public Key
from your Dashboard's project settings and the <CONFIG-KEY>
from the last step.
import Nango from 'https://unpkg.com/@nangohq/frontend/dist/index.js'; // For quick testing
// or
import Nango from '@nangohq/frontend'; // After installing the npm package
var nango = new Nango({ publicKey: '<PUBLIC-KEY>' });
// Trigger an OAuth flow
// Param 1: config key from Step 2 (bullet 4)
// Param 2: ID you will use to retrieve the connection (most often the user ID)
nango
.auth('<CONFIG-KEY>', '<CONNECTION-ID>')
.then((result) => {
console.log(`OAuth flow succeeded for provider "${result.providerConfigKey}" and connection-id "${result.connectionId}"!`);
})
.catch((error) => {
console.error(`There was an error in the OAuth flow for integration: ${error.message}`);
});
import Nango from 'https://unpkg.com/@nangohq/frontend/dist/index.js'; // For quick testing
// or
import Nango from '@nangohq/frontend'; // After installing the npm package
var nango = new Nango({ host: 'http://localhost:3003' });
// Trigger an OAuth flow
// Param 1: config key from Step 2 (bullet 4)
// Param 2: ID you will use to retrieve the connection (most often the user ID)
nango
.auth('<CONFIG-KEY>', '<CONNECTION-ID>')
.then((result) => {
console.log(`OAuth flow succeeded for provider "${result.providerConfigKey}" and connection-id "${result.connectionId}"!`);
})
.catch((error) => {
console.error(`There was an error in the OAuth flow for integration: ${error.message}`);
});
import Nango from 'https://unpkg.com/@nangohq/frontend/dist/index.js'; // For quick testing
// or
import Nango from '@nangohq/frontend'; // After installing the npm package
var nango = new Nango({ host: '<NANGO-HOST-AND-PORT>' });
// Trigger an OAuth flow
// Param 1: config key from Step 2 (bullet 4)
// Param 2: ID you will use to retrieve the connection (most often the user ID)
nango
.auth('<CONFIG-KEY>', '<CONNECTION-ID>')
.then((result) => {
console.log(`OAuth flow succeeded for provider "${result.providerConfigKey}" and connection-id "${result.connectionId}"!`);
})
.catch((error) => {
console.error(`There was an error in the OAuth flow for integration: ${error.message}`);
});
If you are using server side rendering (SSR) with NextJS, use this workaround.
With the frontend part ready, you should now be able to run a full OAuth flow from your app while Nango will retrieve, store and refresh tokens automatically.
Go ahead & try it! 🙌
Step 4: Obtain the access token from the backend​
There are a few different way in which you can obtain access tokens from Nango. The dashboard is great for testing, but in your app we recommend using the node SDK or the Connections REST API.
Make sure you always have a fresh access token
Many OAuth providers provide short-lived access tokens (30-60 minutes). Nango refreshes them automatically for you, but it is important that you always request the access token right before each API call. Otherwise you may work with a stale token that has been revoked and your API call will fail.
Dashboard​
Find the Connection in your dashboard's Connections
page. Click "View" to see the current access token and details.
Backend SDK​
If you work with Node, Nango offers a Node SDK to retrieve tokens (more languages coming).
- Nango Cloud
- Localhost
- Self-hosted
You will need the Secret Key
from your Dashboard's project settings.
import { Nango } from '@nangohq/node';
let nango = new Nango({ secretKey: '<SECRET-KEY>' });
let accessToken = await nango.getToken('<CONFIG-KEY>', '<CONNECTION-ID>');
import { Nango } from '@nangohq/node';
let nango = new Nango({ host: 'http://localhost:3003' });
let accessToken = await nango.getToken('<CONFIG-KEY>', '<CONNECTION-ID>');
import { Nango } from '@nangohq/node';
let nango = new Nango({ host: '<NANGO-HOST-AND-PORT>' });
let accessToken = await nango.getToken('<CONFIG-KEY>', '<CONNECTION-ID>');
REST API​
You can also use the Nango Connections REST API to retrieve connection details & the current access token:
- Nango Cloud
- Localhost
- Self-hosted
You will need the Secret Key
from your Dashboard's project settings.
curl 'https://api.nango.dev/connection/<CONNECTION-ID>?provider_config_key=<CONFIG-KEY>'\
-H 'Authorization: Bearer <SECRET-KEY>'
curl 'http://localhost:3003/connection/<CONNECTION-ID>?provider_config_key=<CONFIG-KEY>'
curl '<NANGO-HOST-AND-PORT>/connection/<CONNECTION-ID>?provider_config_key=<CONFIG-KEY>'
Need help?​
If you run into any trouble whilst setting up Nango or have any questions please do not hesitate to contact us - we are happy to help!
Please join our Slack community, where we are very active, and we will do our best to help you fast.