How it works
- You register an OAuth app with the service and get a
client_idandclient_secret - Your app calls
client.connect.createLink()and redirects the user to the returned URL - After the user approves, the service redirects back with an authorization code
- Corsair exchanges the code for access and refresh tokens and stores them encrypted
- On every API call, Corsair checks token expiry and refreshes automatically
client.connect.createLink() and redirect the user to the returned URL. See Connect / OAuth for the full reference.
corsair.ts
Solo setup
Solo mode connects a single account to your application. Use this for scripts, internal tools, or apps that only ever connect one account.corsair.ts
usage.ts
Multi-tenant setup
In multi-tenant mode, each user connects their own account. Configure Hub and mount the management handler.corsair.ts
app/api/corsair/[[...path]]/route.ts
1. Store your OAuth app credentials
Store your client credentials once. These are shared across all tenants:2. Create a connect link
When a user wants to connect, mint a link from your authenticated backend and redirect them:app/actions/connect.ts
connect-button.tsx
state is embedded in connectUrl. Hub hosts the connect page and OAuth callback, so you do not build those routes yourself.
3. Make API calls per tenant
usage.ts
Automatic token refresh
OAuth access tokens expire (typically after 1 hour). Corsair checks token expiry before every API call and refreshes automatically using the stored refresh token. A read that still comes back 401 gets one more refresh and is repeated. Your code never needs to handle token expiry. It does see a refresh the provider refuses:AuthMissingError with reason: 'revoked' when the user has withdrawn access and has to reconnect, or OAuthRefreshError when your OAuth app’s credentials were rejected or the token endpoint failed. See Expired OAuth tokens.
See Authentication for more details.