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

# Exchange OAuth code for tokens



## OpenAPI

````yaml https://api.crosmos.dev/openapi.json post /api/v1/auth/oauth/{provider}/callback
openapi: 3.1.0
info:
  title: Crosmos API
  version: 0.1.0
servers:
  - url: /
security: []
paths:
  /api/v1/auth/oauth/{provider}/callback:
    post:
      tags:
        - oauth-consumer
      summary: Exchange OAuth code for tokens
      parameters:
        - schema:
            type: string
          required: true
          name: provider
          in: path
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OAuthCallbackRequest'
      responses:
        '200':
          description: Token pair
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OAuthCallbackResponse'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OAuthErrorBody'
        '401':
          description: Invalid state or code
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OAuthErrorBody'
components:
  schemas:
    OAuthCallbackRequest:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          maxLength: 2048
        state:
          type: string
          minLength: 1
          maxLength: 2048
        redirect_uri:
          type: string
          maxLength: 2048
          format: uri
      required:
        - code
        - state
        - redirect_uri
    OAuthCallbackResponse:
      allOf:
        - $ref: '#/components/schemas/TokenPair'
        - type: object
          properties:
            is_new_user:
              type: boolean
            default_space_id:
              type: string
              nullable: true
              format: uuid
          required:
            - is_new_user
            - default_space_id
    OAuthErrorBody:
      type: object
      properties:
        detail:
          type: string
      required:
        - detail
    TokenPair:
      type: object
      properties:
        user_id:
          type: string
          format: uuid
        email:
          type: string
          format: email
        name:
          type: string
        access_token:
          type: string
        refresh_token:
          type: string
        token_type:
          type: string
          enum:
            - bearer
        active_org_id:
          type: string
          nullable: true
          format: uuid
      required:
        - user_id
        - email
        - name
        - access_token
        - refresh_token
        - token_type
        - active_org_id

````