Skip to main content
const session = await airstore.oauth.createSession({
  integrationType: 'gmail',
  workspaceId: 'ws_abc123',
})
// Redirect user to session.authorize_url
The OAuth resource handles interactive connection flows where users authorize access in their browser. Create a session, redirect the user, then poll for completion.

createSession()

Create an OAuth session and get the authorization URL.
const session = await airstore.oauth.createSession({
  integrationType: 'gmail',
  workspaceId: 'ws_abc123',
  returnTo: 'https://app.example.com/settings',
})

console.log(session.authorize_url)
// "https://accounts.google.com/o/oauth2/v2/auth?..."
Redirect the user to authorize_url in their browser. After they approve, Airstore handles the callback. Parameters
ParameterTypeRequiredDescription
integrationTypeIntegrationTypeYesProvider: gmail, gdrive, github, notion, linear, slack
workspaceIdstringNoWorkspace to attach the connection to. Required for org/admin tokens; optional for workspace tokens (derived from the token).
returnTostringNoURL to redirect to after OAuth completes (same-tab flow). If omitted, a static success/error page is shown.
Returns Promise<OAuthSession>
FieldTypeDescription
session_idstringSession ID for polling
authorize_urlstringURL to redirect the user to

getSession()

Check the current status of an OAuth session.
const status = await airstore.oauth.getSession('sess_abc123')

console.log(status.status) // "pending" | "complete" | "error"
Parameters
ParameterTypeRequiredDescription
sessionIdstringYesSession ID from createSession
Returns Promise<OAuthSessionStatus>
FieldTypeDescription
statusstringpending, complete, or error
errorstring | undefinedError message if status is error
connection_idstring | undefinedConnection ID if status is complete

poll()

Poll a session until it completes, errors, or times out. This is a convenience wrapper around getSession() that checks at a regular interval.
const result = await airstore.oauth.poll('sess_abc123')
console.log(result.connection_id) // "conn_xyz789"
With custom options:
const result = await airstore.oauth.poll('sess_abc123', {
  timeout: 120_000,  // 2 minutes
  interval: 1_000,   // check every second
})
Parameters
ParameterTypeRequiredDefaultDescription
sessionIdstringYesSession ID from createSession
timeoutnumberNo300000Max time to wait in ms (5 minutes)
intervalnumberNo2000Polling interval in ms
Returns Promise<OAuthSessionStatus> — resolves with status: "complete". Throws
  • AirstoreError if the session status is error (user denied, provider error, etc.)
  • AirstoreError if the timeout is reached before the session completes