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

# Exchange the SSO code for a token

> The one-time sign-in code and the value kept by the tab become the session.



## OpenAPI

````yaml openapi/en/control.json POST /v1/auth/sso/exchange
openapi: 3.1.0
info:
  title: Niadra control API
  version: '1'
  description: >-
    Tenants, projects, sources, keys, people, configuration and usage. It never
    receives customer content.
servers:
  - url: https://control.api.niadra.com
security: []
paths:
  /v1/auth/sso/exchange:
    post:
      summary: Exchange the SSO code for a token
      description: >-
        The session for a one-time sign-in code and the value the Console kept
        for the tab. When the tenant

        asks for the Niadra second factor, the answers are those of the password
        login: 401 "second factor

        enrollment required" (then POST /v1/auth/sso/second-factor) or "invalid
        second factor"; the code stays

        valid for five wrong codes and ten minutes.


        **Authentication.** No authentication.
      operationId: exchange_v1_auth_sso_exchange_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SsoExchangeRequest'
            example:
              code: bXktb25lLXRpbWUtc2lnbi1pbi1jb2Rl
              verifier: dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TokenOut'
              example:
                access_token: >-
                  eyJhbGciOiJFZERTQSIsImtpZCI6ImN0bC0yMDI2LTA5In0.eyJzdWIiOiIwMTkyZjBhMC00ZTVmIiwiZXhwIjoxNzU4NTYyMTIzfQ.Q2sX...
                token_type: Bearer
                expires_in: 900
                space_id: 0192f0a0-3d4e-7f50-8b61-7c8d9e0f1a24
                recovery_codes: null
                recovery_codes_left: null
          description: The token, as at the password login.
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: The request does not match the contract.
      security: []
components:
  schemas:
    SsoExchangeRequest:
      additionalProperties: false
      properties:
        code:
          description: >-
            The one-time sign-in code the control plane put in the fragment of
            the Console address.
          maxLength: 128
          minLength: 20
          title: Code
          type: string
        recovery_code:
          anyOf:
            - maxLength: 32
              minLength: 10
              type: string
            - type: 'null'
          title: Recovery Code
        space_id:
          anyOf:
            - format: uuid
              type: string
            - type: 'null'
          title: Space Id
        totp:
          anyOf:
            - pattern: ^\d{6}$
              type: string
            - type: 'null'
          description: When the tenant asks for the Niadra second factor.
          title: Totp
        verifier:
          description: The value whose SHA-256 went as `binding`.
          maxLength: 128
          minLength: 20
          title: Verifier
          type: string
      required:
        - code
        - verifier
      title: SsoExchangeRequest
      type: object
    TokenOut:
      additionalProperties: false
      properties:
        access_token:
          title: Access Token
          type: string
        expires_in:
          title: Expires In
          type: integer
          description: Seconds until the token expires.
        recovery_codes:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          description: >-
            Shown once: the ten recovery codes, when this login confirmed the
            authenticator. Null otherwise.
          title: Recovery Codes
        recovery_codes_left:
          anyOf:
            - type: integer
            - type: 'null'
          description: >-
            How many recovery codes remain, when this login used one. Null
            otherwise.
          title: Recovery Codes Left
        space_id:
          format: uuid
          title: Space Id
          type: string
        token_type:
          default: Bearer
          title: Token Type
          type: string
      required:
        - access_token
        - expires_in
        - space_id
      title: TokenOut
      type: object
    Problem:
      additionalProperties: false
      description: RFC 9457 problem details; `code` comes from the versioned error catalog.
      properties:
        code:
          title: Code
          type: string
        detail:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Detail
        request_id:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Request Id
        status:
          title: Status
          type: integer
        title:
          title: Title
          type: string
        type:
          default: about:blank
          title: Type
          type: string
      required:
        - title
        - status
        - code
      title: Problem
      type: object

````