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

# Set per-user token exchange and custom headers on a catalog

> Set per-user token exchange (route the catalog through Gravitino, which runs this
catalog's own exchange chain) and its custom headers. A step's client secret is write-only:
leave it empty to keep the stored one, which is kept only while that step's token URL and client
id are unchanged. The Trino catalog is re-registered to match; Spark and Gravitino pick the
change up live (Gravitino within its cache TTL, 30 s by default).



## OpenAPI

````yaml put /api/metastore/catalogs/{catalog_name}/token-exchange
openapi: 3.1.0
info:
  title: Nx1 AI API
  description: |

    AI API for Nx1 Data Platform Management and Automated Data Tasks.

    Authentication is required via PSK in Authorization header.

    Default PSK is | [ask a friend] |
  version: 0.10.2
servers: []
security: []
paths:
  /api/metastore/catalogs/{catalog_name}/token-exchange:
    put:
      tags:
        - Metastore
      summary: Set per-user token exchange and custom headers on a catalog
      description: >-
        Set per-user token exchange (route the catalog through Gravitino, which
        runs this

        catalog's own exchange chain) and its custom headers. A step's client
        secret is write-only:

        leave it empty to keep the stored one, which is kept only while that
        step's token URL and client

        id are unchanged. The Trino catalog is re-registered to match; Spark and
        Gravitino pick the

        change up live (Gravitino within its cache TTL, 30 s by default).
      operationId: >-
        update_catalog_token_exchange_api_metastore_catalogs__catalog_name__token_exchange_put
      parameters:
        - name: catalog_name
          in: path
          required: true
          schema:
            type: string
            title: Catalog Name
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateCatalogTokenExchangeRequest'
      responses:
        '200':
          description: Catalog updated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatusResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - OAuth2AuthorizationCodeBearer: []
        - APIKeyHeader: []
components:
  schemas:
    UpdateCatalogTokenExchangeRequest:
      properties:
        enabled:
          type: boolean
          title: Enabled
          description: >-
            Enable per-user token exchange: the catalog is routed through
            Gravitino, which authenticates to the remote as the end user. False
            restores the direct path.
        settings:
          anyOf:
            - $ref: '#/components/schemas/TokenExchangeSettings'
            - type: 'null'
          description: >-
            The catalog's exchange settings. Required to enable unless already
            stored; omit to keep the stored settings. Disabling keeps them, so
            turning it back on restores them.
        custom_headers:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Custom Headers
          description: >-
            Replace the catalog's custom headers (name -> value). An empty
            object clears them; omit the field to leave them unchanged.
      type: object
      required:
        - enabled
      title: UpdateCatalogTokenExchangeRequest
      description: >-
        Set per-user token exchange and custom headers on an existing Iceberg
        REST catalog.
    StatusResponse:
      properties:
        success:
          type: boolean
          title: Success
          description: Indicates whether the task completed successfully.
      type: object
      required:
        - success
      title: StatusResponse
    ErrorResponse:
      properties:
        error:
          type: string
          title: Error
          description: A brief description of the error that occurred.
        code:
          type: integer
          title: Code
          description: The HTTP status code associated with the error.
          default: 500
      type: object
      required:
        - error
      title: ErrorResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    TokenExchangeSettings:
      properties:
        trusted_actors:
          items:
            type: string
          type: array
          title: Trusted Actors
          description: >-
            Principals (engine service accounts) that may name the user they act
            for. Trino and Spark need to be listed here, and need an
            impersonation step.
        on_behalf_of_header:
          type: string
          maxLength: 128
          title: On Behalf Of Header
          description: Header a trusted actor names the user in (Spark).
          default: X-Nx1-On-Behalf-Of
        impersonation:
          anyOf:
            - $ref: '#/components/schemas/TokenExchangeStep'
            - type: 'null'
          description: >-
            How a trusted actor's named user becomes that user's own token (e.g.
            Keycloak impersonation).
        steps:
          items:
            $ref: '#/components/schemas/TokenExchangeStep'
          type: array
          title: Steps
          description: >-
            Calls from the user's token to the remote's, in order; each output
            feeds the next.
        cache_skew_seconds:
          type: integer
          maximum: 3600
          minimum: 0
          title: Cache Skew Seconds
          description: Mint a new token this many seconds before the old one expires.
          default: 60
      type: object
      title: TokenExchangeSettings
      description: >-
        A catalog's per-user token exchange: who may act for a user, how a named
        user becomes

        their own token, and the chain from that token to one the remote catalog
        accepts.
    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
    TokenExchangeStep:
      properties:
        name:
          type: string
          maxLength: 64
          title: Name
          description: Label for this step, shown in logs and the form.
          default: ''
        token_url:
          type: string
          maxLength: 2048
          title: Token Url
          description: Token endpoint the step POSTs to.
        grant_type:
          type: string
          maxLength: 256
          title: Grant Type
          description: '`grant_type`; empty means RFC 8693 token exchange.'
          default: ''
        client_auth:
          anyOf:
            - type: string
              enum:
                - basic
                - post
                - none
            - type: 'null'
          title: Client Auth
          description: >-
            How the client authenticates: HTTP Basic,
            `client_id`/`client_secret` in the form, or not at all. Empty means
            Basic when a client id is set, else none.
        client_id:
          type: string
          maxLength: 256
          title: Client Id
          description: Client id, if the endpoint needs one.
          default: ''
        client_secret:
          anyOf:
            - type: string
              maxLength: 4096
            - type: 'null'
          title: Client Secret
          description: >-
            Client secret. Write-only: never returned. Omit or leave empty to
            keep the stored secret, which is kept only while the token URL and
            client id are unchanged.
        subject_param:
          type: string
          maxLength: 64
          title: Subject Param
          description: >-
            Form field for the incoming token; empty means `subject_token`
            (`assertion` for JWT bearer).
          default: ''
        subject_token_type:
          type: string
          maxLength: 256
          title: Subject Token Type
          description: >-
            `subject_token_type`; empty means `access_token` for the
            token-exchange grant.
          default: ''
        user_param:
          type: string
          maxLength: 64
          title: User Param
          description: >-
            For the impersonation step: form field naming the user; empty means
            `requested_subject`.
          default: ''
        requested_token_type:
          type: string
          maxLength: 256
          title: Requested Token Type
          description: >-
            `requested_token_type`; empty means `access_token` for the
            token-exchange grant.
          default: ''
        audience:
          type: string
          maxLength: 1024
          title: Audience
          description: '`audience`, if any.'
          default: ''
        scope:
          type: string
          maxLength: 1024
          title: Scope
          description: '`scope`, if any.'
          default: ''
        resource:
          type: string
          maxLength: 2048
          title: Resource
          description: '`resource`, if any.'
          default: ''
        params:
          additionalProperties:
            type: string
          type: object
          title: Params
          description: >-
            Extra form parameters sent verbatim, e.g.
            `requested_token_use=on_behalf_of`.
        token_field:
          type: string
          maxLength: 64
          title: Token Field
          description: Response field holding the token; empty means `access_token`.
          default: ''
        verify_tls:
          type: boolean
          title: Verify Tls
          description: Verify the endpoint's TLS certificate.
          default: true
      type: object
      required:
        - token_url
      title: TokenExchangeStep
      description: >-
        One call to an OAuth2 token endpoint. Generic over providers: Keycloak,
        Google's STS

        (Workload Identity Federation), Entra ID on-behalf-of and other RFC
        8693-style endpoints are

        just different values here.
  securitySchemes:
    OAuth2AuthorizationCodeBearer:
      type: oauth2
      flows:
        authorizationCode:
          scopes: {}
          authorizationUrl: >-
            https://sso-rapid.rapid.nx1cloud.com/realms/rapid/protocol/openid-connect/auth
          tokenUrl: >-
            https://sso-rapid.rapid.nx1cloud.com/realms/rapid/protocol/openid-connect/token
    APIKeyHeader:
      type: apiKey
      in: header
      name: Authorization-PSK

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.