Before following this guide, configure an integration in the Nango dashboard by selecting a provider and entering your OAuth app credentials. See the Auth overview for context on providers, integrations, and connections.
Prerequisites
- A Nango account and project set up at app.nango.dev
- At least one integration configured in the dashboard
- Your Nango secret key from Environment Settings
- The
@nangohq/nodeSDK installed in your backend
How it works
The authorization flow involves three parties: your backend, your frontend, and Nango. Your backend generates a short-lived session token, your frontend uses it to open the Connect UI, and Nango handles the OAuth flow. After the user authorizes, Nango sends a webhook to your backend with the connection ID.Step 1: Generate a session token (backend)
Set up an endpoint in your backend that your frontend calls before each authorization attempt. This endpoint requests a session token from Nango and returns it to your frontend.- TypeScript
- cURL
The
tags object lets you associate a connection with users, organizations, or other entities in your system. Nango includes these tags in auth webhooks so you can reconcile the generated connection ID with the right entity. Most apps use end_user_id, end_user_email, and organization_id. See Connection management for more on tags.allowed_integrations field controls what the user sees:
- Passing multiple integration IDs shows a list of integrations the user can pick from
- Passing a single integration ID sends the user directly to that integration’s authorization flow
Step 2: Trigger the auth flow (frontend)
In your frontend, install the Nango frontend SDK:openConnectUI() call renders the Connect UI in a full-screen iframe. The UI handles the entire authorization flow, including OAuth redirects and API-key collection forms.
The Connect UI is recommended, but optional. If you need full control over the authorization UX — for example, to build a custom form for API key entry — see the Connect UI guide for details on using
nango.auth() directly.Step 3: Save the connection ID (backend)
After the user authorizes, Nango creates a connection and sends aPOST webhook to your backend with the connection ID. You persist this ID associated with the user or organization in your database.
Configure the webhook:
- Go to Environment Settings in the Nango dashboard
- Set a Webhook URL pointing to an endpoint in your backend
- Enable Send New Connection Creation Webhooks
connectionId value alongside the entity it belongs to in your system.
Step 4: Test the flow
Run the authorization flow from your app and confirm a new connection appears in the Connections tab of the Nango dashboard. If a flow fails, check the Logs tab for a detailed error breakdown.Step 5: Set up a custom OAuth callback URL (optional)
By default, Nango usesapi.nango.dev as the OAuth callback domain. Some providers (such as Google and Zoom) require domain verification or show the callback domain to users during the flow. Setting up a custom callback URL lets you use your own domain.
- Add an endpoint in your app, for example
https://example.com/oauth-callback, that performs a 308 redirect tohttps://api.nango.dev/oauth/callback, preserving all query parameters - Register the new URL as the OAuth callback with each provider’s developer console
- Update the Callback URL in Environment Settings in the Nango dashboard
Step 6: Re-authorize an existing connection
When a connection’s credentials expire or scopes change, you can re-authorize without deleting the connection. Re-authorization updates the credentials while preserving all associated data and configuration. Detect an invalid connection by callinggetConnection() and checking for a 4xx response:
- TypeScript
- cURL
- TypeScript
- cURL
"operation": "override".
Environment variables
| Variable | Description |
|---|---|
NANGO_SECRET_KEY | Your Nango secret key, found in Environment Settings. Keep this server-side only. |
Next steps
Connect UI
Customize the Connect UI appearance and use a connect link for email-based flows.
Connection management
Retrieve credentials, set metadata, and manage connections programmatically.