Skip to main content
OAuth 2.0 lets users authorize your application to act on their behalf. Corsair handles the entire flow — minting connect links, processing callbacks, storing tokens encrypted, and refreshing them automatically when they expire.

How it works

  1. You register an OAuth app with the service and get a client_id and client_secret
  2. Your app calls client.connect.createLink() and redirects the user to the returned URL
  3. After the user approves, the service redirects back with an authorization code
  4. Corsair exchanges the code for access and refresh tokens and stores them encrypted
  5. On every API call, Corsair checks token expiry and refreshes automatically
Corsair supports two connect modes — 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
Store your OAuth app credentials, then start the flow:
The CLI prints an authorization URL. Open it in a browser, approve, and tokens are stored automatically. After that, all API calls use your connected account:
usage.ts
Tokens are refreshed automatically when they expire — no intervention needed.

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:
When a user wants to connect, mint a link from your authenticated backend and redirect them:
app/actions/connect.ts
Or from the client via the management client:
connect-button.tsx
The signed 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
Corsair extracts the 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, use hub: { ... } 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.

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. Your code never needs to handle token expiry. See Authentication for more details.