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

# Google Oauth Callback

> Handle Google OAuth 2.0 callback.

This endpoint:
1. Exchanges the authorization code for user information from Google
2. Creates or updates the user in the database
3. Verifies the user has access to the specified tenant
4. Issues a JWT token with user_id, tenant_id, role, and expiration

Args:
    request: Google OAuth callback request with code and tenant_id
    db: Async database session

Returns:
    TokenResponse: JWT token and user information

Raises:
    HTTPException 400: If Google OAuth validation fails
    HTTPException 403: If user doesn't have access to the tenant



## OpenAPI

````yaml /openapi.json post /auth/google/callback
openapi: 3.1.0
info:
  title: Factio SRI API
  description: >-
    Plataforma headless, multi-tenant, API-first para emitir comprobantes
    electrónicos válidos ante el SRI de Ecuador.


    ## Autenticación


    Soporta tres métodos:

    - **JWT Bearer por Google OAuth**: `/auth/google/callback`

    - **JWT Bearer por email/password**: `/auth/login`

    - **API Key**: header `X-API-Key` con clave generada en `/auth/api-keys`


    ## Multi-tenant


    El aislamiento por tenant combina PostgreSQL RLS y validaciones explícitas
    en backend. El `tenant_id` se resuelve desde el contexto de autenticación.


    ## Flujo de Emisión


    1. `POST /documents` — reserva secuencial y encola el documento (responde
    202)

    2. `GET /documents/{id}` — consulta el estado actual por polling

    3. Cuando `status = AUTHORIZED`, el campo `authorization_number` contiene la
    clave de autorización del SRI


    Documentación completa en https://docs.factioapp.com
  version: 0.1.0
servers:
  - url: http://localhost:8000
    description: Local
  - url: https://api.factioapp.com
    description: Producción
  - url: https://api.staging.factioapp.com
    description: Sandbox (datos de prueba, sin efecto fiscal real)
security: []
paths:
  /auth/google/callback:
    post:
      tags:
        - Authentication
      summary: Google Oauth Callback
      description: |-
        Handle Google OAuth 2.0 callback.

        This endpoint:
        1. Exchanges the authorization code for user information from Google
        2. Creates or updates the user in the database
        3. Verifies the user has access to the specified tenant
        4. Issues a JWT token with user_id, tenant_id, role, and expiration

        Args:
            request: Google OAuth callback request with code and tenant_id
            db: Async database session

        Returns:
            TokenResponse: JWT token and user information

        Raises:
            HTTPException 400: If Google OAuth validation fails
            HTTPException 403: If user doesn't have access to the tenant
      operationId: google_oauth_callback_auth_google_callback_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GoogleCallbackRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TokenResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    GoogleCallbackRequest:
      properties:
        code:
          type: string
          title: Code
          description: Authorization code from Google OAuth
        tenant_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Tenant Id
          description: Tenant ID to associate with the session
        redirect_uri:
          anyOf:
            - type: string
            - type: 'null'
          title: Redirect Uri
          description: Redirect URI used in the Google OAuth authorization request
      type: object
      required:
        - code
      title: GoogleCallbackRequest
    TokenResponse:
      properties:
        access_token:
          type: string
          title: Access Token
          description: JWT access token
        token_type:
          type: string
          title: Token Type
          description: Token type
          default: bearer
        expires_in:
          type: integer
          title: Expires In
          description: Token expiration time in seconds
        user_id:
          type: string
          format: uuid
          title: User Id
          description: User's unique identifier
        tenant_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Tenant Id
          description: Active tenant ID
        role:
          type: string
          title: Role
          description: User's role in the tenant
      type: object
      required:
        - access_token
        - expires_in
        - user_id
        - role
      title: TokenResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    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

````