> ## 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.

# Create or update an external auth provider

> Creates a new external auth provider or updates an existing one.
If a provider with the same `provider_id` exists, it will be updated.
Requires tenant admin authentication.




## OpenAPI

````yaml api/openapi-integration.yaml post /api/v1/admin/auth/providers
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/admin/auth/providers:
    post:
      tags:
        - Auth
      summary: Create or update an external auth provider
      description: |
        Creates a new external auth provider or updates an existing one.
        If a provider with the same `provider_id` exists, it will be updated.
        Requires tenant admin authentication.
      operationId: upsertAuthProvider
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExternalAuthProviderInput'
            examples:
              create:
                summary: Create a new provider
                value:
                  provider_id: my-app
                  display_name: My Application
                  issuer: https://auth.example.com
                  jwks_uri: https://auth.example.com/.well-known/jwks.json
                  allowed_audiences:
                    - api://my-app
                  auto_create_users: true
                  default_membership_tier: ORDINARY
      responses:
        '200':
          description: Provider created or updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExternalAuthProvider'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  schemas:
    ExternalAuthProviderInput:
      type: object
      required:
        - provider_id
        - display_name
        - issuer
        - jwks_uri
        - allowed_audiences
      properties:
        provider_id:
          type: string
          minLength: 1
          maxLength: 100
          description: Unique identifier for this provider
        display_name:
          type: string
          minLength: 1
          maxLength: 255
          description: Human-readable name
        issuer:
          type: string
          format: uri
          description: OIDC issuer URL (must use HTTPS)
        jwks_uri:
          type: string
          format: uri
          description: JSON Web Key Set endpoint (must use HTTPS)
        allowed_audiences:
          type: array
          items:
            type: string
          minItems: 1
          description: Valid audience values for tokens
        auto_create_users:
          type: boolean
          default: true
          description: Whether to auto-create users on first token exchange
        default_membership_tier:
          type: string
          default: ORDINARY
          description: Tier assigned to auto-created users
        user_id_claim:
          type: string
          default: sub
          description: JWT claim containing the user's external ID
        email_claim:
          type: string
          default: email
          description: JWT claim containing the user's email
        name_claim:
          type: string
          default: name
          description: JWT claim containing the user's display name
        is_active:
          type: boolean
          default: true
          description: Whether this provider is active
    ExternalAuthProvider:
      type: object
      properties:
        id:
          type: string
          format: uuid
        provider_id:
          type: string
          description: Unique identifier for this provider
        display_name:
          type: string
          description: Human-readable name
        issuer:
          type: string
          format: uri
          description: OIDC issuer URL
        jwks_uri:
          type: string
          format: uri
          description: JSON Web Key Set endpoint
        allowed_audiences:
          type: array
          items:
            type: string
          description: Valid audience values for tokens
        auto_create_users:
          type: boolean
          description: Whether to auto-create users on first token exchange
        default_membership_tier:
          type: string
          description: Tier assigned to auto-created users
        is_active:
          type: boolean
          description: Whether this provider is active
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    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
    Unauthorized:
      description: Unauthorized - invalid or missing API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: Invalid API key
            code: UNAUTHORIZED
  securitySchemes:
    TenantApiKey:
      type: apiKey
      in: header
      name: x-tenant-api-key
      description: Tenant API key for authentication

````