Authorize in your app (default UI)
Guide to letting your users authorize an external API from your application.
Pre-requisite: complete the Configuration guide.
Authorization overview.
1. Generate a session token (backend)
In your backend, set up an API endpoint that your frontend will call before each authorization attempt to retrieve a session token from Nango.
Here’s an example of how your backend can retrieve a session token from Nango (API / Node SDK references):
ℹ️ Details on end user and organization information
ℹ️ Details on end user and organization information
The end_user
and organization
information fields help identify which connection belongs to which end user and organization. This information is also used for display purposes in the Nango UI and, in some cases, for custom billing plans.
The end_user.id
is required. Pass in your internal ID of the user who initiated the authorization flow. This ID, and potentially the organization.id
, are necessary for reconciling the connection details that your backend receives from Nango after the connection is created (as described in the section 3).
It’s possible that the end use’s email in your app will not match the email they use to connect their external account, which is fine.
Editing user and org data
Updating data for a user ID or org ID will apply the changes to all connections linked to that ID.
For example, if you create connection A
with user ID X
and email a@a.com
, then connection B
with the same user ID X
and email b@b.com
, both connections will reflect the latest data: b@b.com
. The same applies to org data—editing it updates all connections tied to that org ID.
Passing a list of integration IDs in allowed_integrations
will display a list of integrations that the end user can pick from:
Nango's default authorization UI.
Passing a single integration ID in allowed_integrations
will send the end user directly to this integration’s authorization flow:
Nango's default authorization UI.
2. Trigger the auth flow (frontend)
In your frontend, load the Nango frontend SDK, retrieve the session token from the backend, and trigger the authorization flow.
Option 1: Use the default UI (Nango Connect)
Nango’s default authorization UI comes with pre-built features:
- Displays the necessary input fields, validates their format & provides end-user instructions
- Authorizes a specific integration or can display a list of integrations to choose from
- Is fully whitelabel, without any Nango branding
Nango's default authorization UI.
Option 2: Use your custom UI
Refer to the Authorize in your app (custom UI) guide.
3. Listen for webhooks & save the Connection ID (backend)
👩🏻💻 Simplified flow for development
👩🏻💻 Simplified flow for development
In development, you can retrieve the connection ID without relying on webhooks.
When using the nango.openConnectUI()
method in the frontend SDK, the connection ID is available in the event
parameter of the callback:
However, we do not recommend using this approach in production, as it is safer to avoid exposing the connection ID to the frontend.
The connection ID, a UUID generated by Nango, is required to manage the connection and access its credentials & data. So you need to persist this ID.
Upon successful authorization, Nango will send a webhook to your backend with the connection ID.
To set up this webhook:
- go to the Environment Settings tab in the Nango UI
- specify a Webhook URL where Nango should send notifications
- enable the Send New Connection Creation Webhooks option
- create the specified route in your backend to handle Nango webhooks
Successful authorization webhooks sent by Nango are POST
requests with the following JSON body:
For each successful authorization, persist the connectionId
value alongside its corresponding user or organization, designated by endUser.endUserId
and endUser.organizationId
.
4. Run the authorization flow
You can now test the authorization flow directly from your app and verify that a connection is created in the Nango UI Connections tab.
Troubleshoot authorization errors
If an authorization request fails, you can analyze the relevant log in the Logs tab of the Nango UI.
Re-authorize an existing connection
Details in this guide.
Next
You have successfully set up the authorization flow for your users. Next steps:
- View new connections & associated credentials in the Connections tab of the Nango UI
- Retrieve connection credentials with the API or Node SDK
- Sync data from APIs
- Perform actions with APIs
- Perform direct request to APIs
Questions, problems, feedback? Please reach out in the Slack community.