Re-authorize a connection
Guide on how to re-authorize a connection.
There are cases where you need to re-authorize a connection, e.g. credentials have expired or the scopes/permissions have changed.
The simplest way is to delete and recreate the connection, but this will reset the connection’s attached data (metadata, synced records). Most of the time when testing, this is fine.
Follow the instructions below if you need to re-authorize a connection without altering it’s attached data.
Handle Invalid Connections in Your UI
When rendering integration settings in your application, it’s important to check if existing connections are still valid and provide users with a clear path to fix invalid connections.
Detect invalid connections
Before displaying integration settings, check if the connection is still valid using the GET /connection
endpoint:
Display reconnect UI
If the response is a 4xx error, display an error message and a “Reconnect” button in your UI. When the user clicks the “Reconnect” button, trigger the reauthorization flow using the reconnect session token as described in the next section.
The ideal user flow should be:
- User navigates to integration settings/dashboard
- System detects invalid connection and displays error state
- User clicks “Reconnect” button
- Reauthorization flow is triggered
- Connection is restored and user returns to normal settings view
Re-authorize a connection from your app
This is the recommended way to re-authorize production connections, so customers can re-authorize independently, without having to manually send you their account credentials.
You can implement the re-authorization flow in your app by having your backend call a different endpoint when the connection already exists.
Instead of generating the default endpoint to generate a session token, use the POST /connect/sessions/reconnect
endpoint (API/SDK reference) to generate a session token meant for reconnection. This token is then used on the frontend in the same way as when creating a connection, but it will reconnect the existing connection instead.
Re-authorize a connection from the Nango UI
This is only recommended for test connections, not production connections.
If you do intend to re-authorize a production connection from the Nango UI, be sure to use your customer’s account credentials.
The flow to re-authorize connections from the Nango UI is legacy. It will revamp shortly.
To re-connect from the UI, go to the Connections tab > click Add Test Connection > click Or use deprecated flow. Pick the relevant integration and enter the connection ID of the connection you want to re-authorize.
This flow leverage’s the headless client. Check out the reference to pass the right parameters based on the integration’s authorization type (OAuth, API key, basic auth).