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

# Exchange external JWT for MLM tokens

> Exchanges a JWT from an external identity provider (e.g., Open Ears) for
MLM platform access and refresh tokens. If the user doesn't exist and
auto-creation is enabled for the provider, a new user is created.




## OpenAPI

````yaml api/openapi-integration.yaml post /api/v1/auth/exchange
openapi: 3.1.0
info:
  title: MLM Platform Integration API
  version: 1.0.0
  description: >
    Tenant integrator APIs for external platform federation and member-data
    access,

    including OIDC token exchange, external user linking, genealogy, referrals,
    and commissions.


    ## Authentication

    All API requests require a tenant API key passed in the `x-tenant-api-key`
    header.


    ## Token Exchange

    External platforms can exchange their JWT tokens for MLM platform tokens
    using

    the `/api/v1/auth/exchange` endpoint.
  contact:
    name: MLM Platform Support
    email: support@mlm-platform.example.com
servers:
  - url: https://app.mlm-platform.com
    description: Production API
  - url: http://localhost:3000
    description: Local Development
security:
  - TenantApiKey: []
tags:
  - name: Auth
    description: Authentication and token exchange
  - name: Genealogy
    description: Member hierarchy and relationships
  - name: Referrals
    description: Referral statistics and QR codes
  - name: Commissions
    description: Commission history and breakdowns
  - name: Webhooks
    description: Webhook receivers for third-party providers (Stripe, Wise)
paths:
  /api/v1/auth/exchange:
    post:
      tags:
        - Auth
      summary: Exchange external JWT for MLM tokens
      description: |
        Exchanges a JWT from an external identity provider (e.g., Open Ears) for
        MLM platform access and refresh tokens. If the user doesn't exist and
        auto-creation is enabled for the provider, a new user is created.
      operationId: exchangeToken
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - externalJwt
                - provider
              properties:
                externalJwt:
                  type: string
                  description: JWT from external provider
                token:
                  type: string
                  description: Deprecated alias for externalJwt
                provider:
                  type: string
                  description: Provider ID (e.g., 'open-ears')
            examples:
              basic:
                summary: Token exchange
                value:
                  externalJwt: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
                  provider: open-ears
      responses:
        '200':
          description: Token exchange successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TokenExchangeResult'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          description: Token validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: Token validation failed
                code: TOKEN_EXCHANGE_FAILED
        '403':
          description: User is banned
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: User is banned
                code: USER_BANNED
components:
  schemas:
    TokenExchangeResult:
      type: object
      properties:
        accessToken:
          type: string
        refreshToken:
          type: string
        tokenType:
          type: string
          enum:
            - Bearer
        expiresIn:
          type: integer
        scope:
          type: string
        mlmUserId:
          type: string
          format: uuid
        isNewUser:
          type: boolean
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
        code:
          type: string
        details:
          type: object
  responses:
    BadRequest:
      description: Bad request - validation error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: Validation failed
            code: VALIDATION_ERROR
            details:
              email: Invalid email format
  securitySchemes:
    TenantApiKey:
      type: apiKey
      in: header
      name: x-tenant-api-key
      description: Tenant API key for authentication

````