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
hub (Corsair hosts the UI) or manual (you host connect pages). Both use the same createLink API. 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 manual connect mode 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 — you do not store it separately.
3. Resolve on your connect page
The user lands on/connect?state=…. Resolve the state and redirect to the provider:
app/connect/page.tsx
4. Handle the callback
After the user approves, the provider redirects to your callback URL:app/api/oauth/callback/route.ts
tenantId from the HMAC-signed state, exchanges the code for tokens, and stores them encrypted for that tenant.
See Production: OAuth Process for a full implementation with security best practices — authenticated link creation, HTML escaping, and production checklists.
5. Make API calls per tenant
usage.ts
Hub mode alternative
If you don’t want to build connect pages, usehub: { ... } instead of manual. Call the same createLink API — the URL points to Corsair Hub’s hosted UI. Hub hosts the connect surfaces and stores none of your credentials. See Hub overview for the model and Connect / OAuth for the API.