Skip to main content
OAuth 2.0 lets users authorize your application to act on their behalf. Corsair handles the entire flow through Hub: 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
Hub hosts the connect UI and OAuth callback. Call 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
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 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:
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. 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. Your code never needs to handle token expiry. See Authentication for more details.