> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tetherai.ca/llms.txt
> Use this file to discover all available pages before exploring further.

# Handle WorkOS callback (API response mode)

> Called by the SPA after the browser redirect to finalize the WorkOS session. Exchanges the authorization code, upserts the user, and returns access/refresh tokens plus the resolved session config — the JSON equivalent of the GET callback redirect.



## OpenAPI

````yaml /api-reference/openapi.yaml post /api/auth/workos/callback
openapi: 3.0.3
info:
  title: Tether Relay and Tether API
  version: 1.0.0
  description: >-
    Route-derived OpenAPI contract generated from tether-relay backend sources.
    Regenerate with scripts/sync-openapi-from-backend.mjs.
servers:
  - url: https://your-instance.example.com
    description: Production
  - url: http://localhost:2212
    description: Local API service
security: []
tags:
  - name: AI
  - name: Applications
  - name: Approval
  - name: Auth
  - name: Automations
  - name: Calls
  - name: Campaigns
  - name: Contact Analytics
  - name: Contact Metrics
  - name: Contact Notes
  - name: Contacts
  - name: Conversation Monitor
  - name: Conversations
  - name: Departments
  - name: Email
  - name: Escalation Dashboard
  - name: Event Logs
  - name: Google Sheets
  - name: Marketplace
  - name: Messages
  - name: Notification Sounds
  - name: Notifications
  - name: Org Snapshots
  - name: Organizations
  - name: Outreach
  - name: Outreach Metrics
  - name: Outreach Sources
  - name: Pipelines
  - name: Processes
  - name: Prompts
  - name: Reminders
  - name: Sms
  - name: Templates
  - name: Traces
  - name: Training
  - name: Upload
  - name: User Snapshots
  - name: Users
  - name: Vertical
  - name: Webchats
  - name: Webhook
paths:
  /api/auth/workos/callback:
    post:
      tags:
        - Auth
      summary: Handle WorkOS callback (API response mode)
      description: >-
        Called by the SPA after the browser redirect to finalize the WorkOS
        session. Exchanges the authorization code, upserts the user, and returns
        access/refresh tokens plus the resolved session config — the JSON
        equivalent of the GET callback redirect.
      operationId: post_auth_workos_callback
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AuthWorkOSCallbackRequest'
      responses:
        '200':
          description: Auth session created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthLoginResponse'
        '400':
          description: No authorization code or callback error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthErrorResponse'
        '500':
          description: Callback handling failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthErrorResponse'
components:
  schemas:
    AuthWorkOSCallbackRequest:
      type: object
      properties:
        code:
          type: string
          description: >-
            OAuth authorization code returned by WorkOS/Okta; exchanged
            server-side (SSO first, AuthKit fallback). Required unless `error`
            is set.
        state:
          type: string
          description: >-
            Opaque CSRF state token round-tripped from the original `/authorize`
            call.
        error:
          type: string
          description: >-
            Provider-reported error code; when present the request
            short-circuits with a 400 instead of attempting code exchange.
        redirect_uri:
          type: string
          description: >-
            Redirect URI used in the original `/authorize` call; must match for
            the code exchange to succeed. Falls back to `${CLIENT_URL}/signin`.
        organizationId:
          type: string
          description: >-
            Mongo `_id` used to assign the org when provisioning a brand-new
            WorkOS user; falls back to `DEFAULT_ORGANIZATION_ID` then the oldest
            org.
      additionalProperties: true
      example:
        code: 01HX9R3K4N6P8QZBVTYM2D5A7C
        state: tether-csrf-7f4b2c1d
        redirect_uri: https://app.tether.example/auth/callback
        organizationId: org_01HX9R3K4N6P8QZBVTYM2D5A7C
    AuthLoginResponse:
      type: object
      description: >-
        Returned by `/api/auth/login` and `POST /api/auth/workos/callback` on
        success. Contains access + refresh tokens, session config, and the
        resolved user.
      properties:
        token:
          type: string
          description: JWT access token.
        refreshToken:
          type: string
        sessionConfig:
          $ref: '#/components/schemas/AuthSessionConfig'
        user:
          $ref: '#/components/schemas/AuthUserSummary'
      required:
        - token
        - refreshToken
        - sessionConfig
        - user
      additionalProperties: true
      example:
        token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1Zjdi...
        refreshToken: rt_64d2f9c5e8a1d4e001a0b1c2e6f7a8b9
        sessionConfig:
          enabled: true
          idleTimeoutMinutes: 30
          tokenExpiryHours: 8
          warningTimeMinutes: 2
        user:
          id: 5f7b1c2e8a1d4e0012c3b4a5
          email: admin@acme.example
          fullName: Acme Admin
          organizationId: 64a1b2c3d4e5f60012345678
          accessRole: ADMIN
    AuthErrorResponse:
      type: object
      description: >-
        Generic error envelope returned by Auth endpoints. Most paths include
        only `error`; a few add `details`/`code` for diagnostic context.
      properties:
        error:
          type: string
        details:
          type: string
        code:
          type: string
      required:
        - error
      additionalProperties: true
      example:
        error: Invalid or expired token
        code: TOKEN_EXPIRED
    AuthSessionConfig:
      type: object
      description: >-
        Resolved session configuration returned alongside tokens. Mirrors the
        org-level idle-timeout / SSO renewal policy so the client can enforce
        it.
      properties:
        enabled:
          type: boolean
        idleTimeoutMinutes:
          type: number
        tokenExpiryHours:
          type: number
        warningTimeMinutes:
          type: number
        idleTrackingEnabled:
          type: boolean
        ssoSilentRenewalEnabled:
          type: boolean
        ssoFallbackBehavior:
          type: string
        passwordSilentRenewalEnabled:
          type: boolean
        passwordFallbackBehavior:
          type: string
      required:
        - enabled
      additionalProperties: true
      example:
        enabled: true
        idleTimeoutMinutes: 30
        tokenExpiryHours: 8
        warningTimeMinutes: 2
        idleTrackingEnabled: true
        ssoSilentRenewalEnabled: true
        ssoFallbackBehavior: redirect
        passwordSilentRenewalEnabled: false
        passwordFallbackBehavior: logout
    AuthUserSummary:
      type: object
      description: Compact User payload returned with auth tokens.
      properties:
        id:
          type: string
        email:
          type: string
          format: email
        fullName:
          type: string
        organizationId:
          type: string
        workosOrganizationId:
          type: string
        accessRole:
          type: string
        departmentId:
          type: string
        workosUserId:
          type: string
        conversationOpenPreference:
          type: string
      required:
        - id
        - email
        - organizationId
        - accessRole
      additionalProperties: true
      example:
        id: 5f7b1c2e8a1d4e0012c3b4a5
        email: admin@acme.example
        fullName: Acme Admin
        organizationId: 64a1b2c3d4e5f60012345678
        accessRole: ADMIN
        conversationOpenPreference: split

````