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

# Oauth2 Callback Handler

> Handle OAuth2 callback from the given OAuth client.



## OpenAPI

````yaml /openapi.yaml get /v1/auth/sso/oauth2/callback
openapi: 3.1.0
info:
  title: Knowledge Stack API
  description: Knowledge Stack backend API for authentication and knowledge management
  version: 0.1.0
servers:
  - url: http://localhost:8000
    description: Knowledge Stack API local dev server
security: []
tags:
  - name: auth
    description: Authentication and identity management
  - name: users
    description: User accounts
  - name: tenants
    description: Tenant management
  - name: invites
    description: Tenant invitations
  - name: folders
    description: Folder management
  - name: documents
    description: Document management
  - name: document-versions
    description: Document version management
  - name: sections
    description: Document sections
  - name: chunks
    description: Chunk CRUD and semantic search
  - name: chunk-lineages
    description: Chunk lineage tracking
  - name: tags
    description: Tag management
  - name: path-parts
    description: Path part traversal and tagging
  - name: Threads
    description: Thread conversations
  - name: Thread Messages
    description: Thread message management
  - name: user-permissions
    description: User path permissions
  - name: workflows
    description: Ingestion workflows
paths:
  /v1/auth/sso/oauth2/callback:
    get:
      tags:
        - auth
      summary: Oauth2 Callback Handler
      description: Handle OAuth2 callback from the given OAuth client.
      operationId: oauth2_callback
      parameters:
        - name: provider
          in: query
          required: true
          schema:
            $ref: '#/components/schemas/IdpType'
            description: Provider to initiate SSO with
          description: Provider to initiate SSO with
        - name: code
          in: query
          required: false
          schema:
            type: string
            nullable: true
            description: Authorization code from provider
            title: Code
          description: Authorization code from provider
        - name: state
          in: query
          required: false
          schema:
            type: string
            nullable: true
            description: State parameter for CSRF protection
            title: State
          description: State parameter for CSRF protection
        - name: error
          in: query
          required: false
          schema:
            type: string
            nullable: true
            description: Error code if authorization failed
            title: Error
          description: Error code if authorization failed
        - name: error_description
          in: query
          required: false
          schema:
            type: string
            nullable: true
            description: Error description
            title: Error Description
          description: Error description
        - name: tenant_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
            nullable: true
            description: Tenant ID to initiate SSO with
            title: Tenant Id
          description: Tenant ID to initiate SSO with
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    IdpType:
      type: string
      enum:
        - PASSWORD
        - GOOGLE
        - TENANT
      title: IdpType
      description: Identity provider type.
    UserResponse:
      properties:
        id:
          type: string
          format: uuid
          title: Id
          description: User ID
        email:
          type: string
          nullable: true
          title: Email
          description: Email address of the user
        first_name:
          type: string
          nullable: true
          title: First Name
          description: First name of the user
        last_name:
          type: string
          nullable: true
          title: Last Name
          description: Last name of the user
        idp_type:
          $ref: '#/components/schemas/IdpType'
          description: Identity provider type of the user
        current_tenant_id:
          type: string
          format: uuid
          title: Current Tenant Id
          description: Current tenant ID the user is logged into
        current_tenant_role:
          $ref: '#/components/schemas/TenantUserRole'
          description: Current tenant role of the user
        default_tenant_id:
          type: string
          format: uuid
          title: Default Tenant Id
          description: Default tenant ID the user shall be logged into
      additionalProperties: false
      type: object
      required:
        - id
        - email
        - first_name
        - last_name
        - idp_type
        - current_tenant_id
        - current_tenant_role
        - default_tenant_id
      title: UserResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    TenantUserRole:
      type: string
      enum:
        - USER
        - OWNER
        - ADMIN
      title: TenantUserRole
      description: Tenant user role.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````