openapi: 3.0.3
info:
  title: Auth Service API
  description: |
    Authentication and authorization service for the True Markets platform — issues JWT access/refresh tokens used across the Gateway and other True Markets APIs.

    ## Base URLs

    | Environment | Base URL |
    |---|---|
    | Production | `https://api.truemarkets.co/v1/auth` |
    | UAT (sandbox) | `https://api.uat.truemarkets.co/v1/auth` |

    ## Authentication tutorial

    Programmatic clients use an ECDSA-signed challenge to mint short-lived JWTs. There are two ways in, and each uses its own keys.

    **Gateway (an organization trading for its users).** Create an organization and an API key in the developer console, then mint a token with `POST /api-key/token`. An organization token lasts one hour and has no refresh token, so mint a new one before it expires. Act for a user with `TM-On-Behalf-Of: <user_id>`, and sign that user's payloads with their signer key, not the organization API key.

    **Trading API (your own account).**

    1. **Create an account** at [https://www.truemarkets.co](https://www.truemarkets.co) (passkey, email, magic link, or Sign in with Apple).
    2. **Register an API key** in your account's *API Keys* settings page. Generate an EC P-256 key pair locally and submit only the public key — the private key never leaves your machine. You'll receive a `key_id` (UUID). The same key signs you in and signs your payloads.
    3. **Mint JWTs** by calling `POST /api-key/token` with `key_id`, a current `timestamp` (Unix seconds, within ±30s of server UTC time), and `signature` — an ES256 (ECDSA P-256 + SHA-256) signature of the message `{key_id}.{timestamp}`, base64url-encoded. The response returns `access_token` and `refresh_token`.
    4. **Call True Markets APIs** with `Authorization: Bearer <access_token>`.
    5. **Refresh** expired access tokens via `POST /token/refresh` with the `refresh_token` — no re-signing required.

    ### Quick start

    ```bash
    # 1. Mint a JWT (key_id and signature computed client-side)
    curl -X POST https://api.truemarkets.co/v1/auth/api-key/token \
      -H "Content-Type: application/json" \
      -d '{"key_id":"<UUID>","timestamp":<UNIX_SECONDS>,"signature":"<BASE64URL_ES256_SIG>"}'

    # 2. Fetch JWKS to verify token signatures locally
    curl https://api.truemarkets.co/.well-known/jwks.json

    # 3. Refresh a token before expiry (personal API keys only; an organization mints a new token instead)
    curl -X POST https://api.truemarkets.co/v1/auth/token/refresh \
      -H "Content-Type: application/json" \
      -d '{"refresh_token":"<REFRESH_TOKEN>"}'
    ```

    ## Support
    - 📧 [support@truemarkets.co](mailto:support@truemarkets.co)
  version: 1.3.7
servers:
  - url: https://api.truemarkets.co/v1/auth
    description: Production
  - url: https://api.uat.truemarkets.co/v1/auth
    description: UAT (sandbox)
paths:

  /token/refresh:
    post:
      summary: Refresh access token
      description: Exchange a valid refresh token for a new access/refresh token pair
      operationId: refreshToken
      tags:
        - Authentication
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RefreshTokenRequest"
      responses:
        "200":
          description: Tokens refreshed successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AccessTokensResponse"
        "400":
          description: Invalid request body or missing refresh token
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "401":
          description: Invalid or expired refresh token
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "403":
          $ref: "#/components/responses/AccountDisabled"
        "500":
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /api-key/token:
    post:
      summary: Exchange API key for tokens
      description: |-
        Verify an ECDSA P-256 signature and issue JWT tokens. The client signs
        the message `{key_id}.{unix_timestamp}` with their private key using ES256.
        The timestamp must be within ±30 seconds of the server time.

        A personal key returns an access token and a refresh token. An organization key
        returns an access token only, with no `refresh_token` field: mint a new token from
        the key before `expires_in`.


        **Rate limit:** counts against the Sign-in verification limit, 30 a minute (per ip address, for every caller). See [Rate limits](/developer-resources/rate-limits).
      operationId: exchangeAPIKeyToken
      tags:
        - Authentication
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/APIKeyTokenExchangeRequest"
      responses:
        "200":
          description: Tokens issued successfully. A user key yields an access and refresh token; an organization key yields an access token only.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: "#/components/schemas/AccessTokensResponse"
                  - $ref: "#/components/schemas/OrganizationTokenResponse"
        "400":
          description: Invalid request (missing fields)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "401":
          description: Invalid API key, expired, revoked, invalid signature, or timestamp out of range
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "403":
          $ref: "#/components/responses/AccountDisabled"
        "500":
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
      x-rate-limit: auth_verify

  /oauth/authorize:
    get:
      summary: Start an authorization request
      description: |
        The authorization endpoint (RFC 6749 4.1.1). A valid request is
        redirected to the consent screen with its parameters intact; the
        signed-in user's decision comes back through `/oauth/consent`.

        Where a failure is reported depends on what failed. An unknown client
        or an unregistered `redirect_uri` is answered here, because the only
        target we could redirect to is the one we just refused to trust.
        Everything else redirects back to the client with `error` and `state`
        (RFC 6749 4.1.2.1).

        PKCE is required and `code_challenge_method` must be `S256`.
      operationId: oauthAuthorize
      tags:
        - OAuth
      security: []
      parameters:
        - name: client_id
          in: query
          required: true
          schema:
            type: string
        - name: redirect_uri
          in: query
          required: true
          description: Must match one the client registered, byte-for-byte outside loopback.
          schema:
            type: string
            format: uri
        - name: response_type
          in: query
          required: true
          schema:
            type: string
            enum: [code]
        - name: code_challenge
          in: query
          required: true
          description: base64url SHA-256 of the client's code verifier.
          schema:
            type: string
        - name: code_challenge_method
          in: query
          required: true
          schema:
            type: string
            enum: [S256]
        - name: resource
          in: query
          required: true
          description: RFC 8707 resource indicator; becomes the access token's audience.
          schema:
            type: string
            format: uri
        - name: scope
          in: query
          required: false
          description: Space-delimited. Defaults to every scope the client registered for.
          schema:
            type: string
        - name: state
          in: query
          required: false
          description: Echoed back unchanged so the client can detect an unsolicited response.
          schema:
            type: string
      responses:
        "302":
          description: |
            Redirect to the consent screen, or back to the client's
            `redirect_uri` carrying `error` and `state`.
          headers:
            Location:
              schema:
                type: string
                format: uri
        "400":
          description: Unknown client, or a redirect_uri the client did not register.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OAuthError"
        "401":
          description: The client is unknown or disabled.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OAuthError"

  /oauth/consent:
    post:
      summary: Record a consent decision
      description: |-
        The signed-in user's answer to the consent screen. Approving records
        the grant and mints an authorization code; denying returns the client
        to its redirect with `error=access_denied`.

        The authorize parameters are repeated here and validated again, because
        nothing but the user's browser carries them between the two requests.

        Returns where the browser should go rather than redirecting, since the
        consent screen issues this as a fetch.


        **Rate limit:** counts against the Keys and credentials limit, 10 a minute and 50 a day (user token, per user); 100 a minute and 500 a day (organization api key, per organization). See [Rate limits](/developer-resources/rate-limits).
      operationId: oauthConsent
      tags:
        - OAuth
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ConsentRequest"
      responses:
        "200":
          description: Decision recorded
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ConsentResponse"
        "400":
          description: The authorize parameters no longer validate.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OAuthError"
        "401":
          description: Not authenticated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "403":
          description: |
            `error=login_required` — approving a sensitive scope such as
            `mcp:trade` needs a credential presented within the last few
            minutes, and this session's is older.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OAuthError"
      x-rate-limit: security

  /oauth/token:
    post:
      summary: Exchange a grant for tokens
      description: |-
        The token endpoint (RFC 6749 4.1.3 and 6), form encoded.

        `authorization_code` consumes the code atomically, checks it was issued
        to this client and this `redirect_uri`, and verifies PKCE. A code is
        single-use: unknown, expired and already-redeemed are one answer, so a
        caller cannot tell them apart.

        `refresh_token` rotates: the presented token is consumed and the
        response carries its replacement, minted with the stored audience and
        scopes, so neither can widen on refresh. Refresh tokens are opaque and
        single-use; replaying a consumed one revokes every token descended
        from the same grant.


        **Rate limit:** counts against the Sign-in verification limit, 30 a minute (per ip address, for every caller). See [Rate limits](/developer-resources/rate-limits).
      operationId: oauthToken
      tags:
        - OAuth
      security: []
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              required:
                - grant_type
                - client_id
              properties:
                grant_type:
                  type: string
                  enum: [authorization_code, refresh_token]
                client_id:
                  type: string
                code:
                  type: string
                  description: Required for authorization_code.
                redirect_uri:
                  type: string
                  format: uri
                  description: Required for authorization_code; must match the authorize request.
                code_verifier:
                  type: string
                  description: Required for authorization_code.
                refresh_token:
                  type: string
                  description: Required for refresh_token.
      responses:
        "200":
          description: Tokens issued
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OAuthTokenResponse"
        "400":
          description: |
            `invalid_grant` for a bad, expired, replayed or mismatched code or
            PKCE verifier; `unsupported_grant_type` otherwise.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OAuthError"
        "401":
          description: The client is unknown or disabled.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OAuthError"
      x-rate-limit: auth_verify

  /.well-known/oauth-resource-jwks.json:
    get:
      summary: OAuth resource token key set
      description: |
        The key set for OAuth resource tokens, served separately from
        `/.well-known/jwks.json`.

        Resource tokens are signed with their own key, so a resource token
        presented to a first-party verifier fails signature verification.
        Only resource servers fetch this document.
      operationId: oauthResourceJWKS
      tags:
        - OAuth
      security: []
      responses:
        "200":
          description: The resource token key set
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/JWKSResponse"
  /oauth/authorize/details:
    get:
      summary: Describe an authorization request
      description: |
        What the consent screen renders: who is asking, for what, and whether
        we vouch for the name.

        It validates the same request `/oauth/authorize` did, so the screen
        cannot be made to describe a grant that would not actually be issued.

        `unverified` is true for a client that registered itself and chose its
        own name. `redirect_host` is shown beside the name because the host is
        the part a client cannot assert freely.
      operationId: oauthAuthorizeDetails
      tags:
        - OAuth
      security: []
      parameters:
        - name: client_id
          in: query
          required: true
          schema:
            type: string
        - name: redirect_uri
          in: query
          required: true
          schema:
            type: string
            format: uri
        - name: response_type
          in: query
          required: true
          schema:
            type: string
            enum: [code]
        - name: code_challenge
          in: query
          required: true
          schema:
            type: string
        - name: code_challenge_method
          in: query
          required: true
          schema:
            type: string
            enum: [S256]
        - name: resource
          in: query
          required: true
          schema:
            type: string
            format: uri
        - name: scope
          in: query
          required: false
          schema:
            type: string
        - name: state
          in: query
          required: false
          schema:
            type: string
      responses:
        "200":
          description: The request as the consent screen should present it
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AuthorizeClientResponse"
        "400":
          description: The authorize request does not validate.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OAuthError"
        "401":
          description: The client is unknown or disabled.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OAuthError"

  /oauth/consents:
    get:
      summary: List connected apps
      description: The user's standing OAuth grants, newest first.
      operationId: listOAuthConsents
      tags:
        - OAuth
      security:
        - bearerAuth: []
      responses:
        "200":
          description: The user's live grants
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/ConsentGrantResponse"
        "401":
          description: Not authenticated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /oauth/consents/{client_id}:
    delete:
      summary: Revoke a connected app
      description: |-
        Withdraws the grant and revokes the refresh tokens minted from it, so
        the client cannot mint a fresh access token once its current one
        lapses. An access token already issued stays valid until it expires.


        **Rate limit:** counts against the Keys and credentials limit, 10 a minute and 50 a day (user token, per user); 100 a minute and 500 a day (organization api key, per organization). See [Rate limits](/developer-resources/rate-limits).
      operationId: revokeOAuthConsent
      tags:
        - OAuth
      security:
        - bearerAuth: []
      parameters:
        - name: client_id
          in: path
          required: true
          schema:
            type: string
      responses:
        "204":
          description: Grant revoked
        "401":
          description: Not authenticated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "404":
          description: The user has no live grant for this client.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
      x-rate-limit: security

  /oauth/register:
    post:
      summary: Register an OAuth client
      description: |-
        Dynamic client registration (RFC 7591). A remote MCP client — Claude,
        Meta Muse, MCP Inspector — calls this itself before starting an
        authorization flow; none of them can be handed a `client_id` out of
        band.

        Registration is open in mechanism and closed in reach: every
        `redirect_uri` must belong to one known client vendor, and a caller
        whose callback belongs to none is refused. Clients registered here are
        public, use PKCE with S256, and are marked unverified on the consent
        screen because their name is self-asserted.

        Errors answer in the OAuth envelope (RFC 6749 5.2), not the usual one.


        **Rate limit:** counts against the OAuth client registration limit, 5 a minute and 50 a day (per ip address, for every caller). See [Rate limits](/developer-resources/rate-limits).
      operationId: registerOAuthClient
      tags:
        - OAuth
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RegisterOAuthClientRequest"
      responses:
        "201":
          description: Client registered
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RegisterOAuthClientResponse"
        "400":
          description: |
            Invalid client metadata, or a redirect_uri belonging to no known
            vendor. `error` is `invalid_redirect_uri`, `invalid_client_metadata`
            or `invalid_scope`.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OAuthError"
        "500":
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
      x-rate-limit: oauth_register

  /.well-known/oauth-authorization-server:
    servers:
      - url: https://api.truemarkets.co
        description: Production
      - url: https://api.uat.truemarkets.co
        description: UAT
    get:
      summary: Authorization server metadata
      description: |
        RFC 8414 discovery. A remote MCP client fetches this to learn where to
        register and authorize, having been configured with nothing but the
        MCP server URL.

        `issuer` must equal the origin this document is served from, which is
        why it is mounted at the root rather than under `/v1/auth`. The
        endpoints it names do sit under that base path; RFC 8414 does not
        require them to share the issuer's prefix.

        Served `no-store`: a client that cached this across a key or endpoint
        rotation would fail in a way that looks like our outage.
      operationId: oauthAuthorizationServerMetadata
      tags:
        - OAuth
      security: []
      responses:
        "200":
          description: The authorization server's published identity
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AuthorizationServerMetadata"

components:
  responses:
    AccountDisabled:
      description: An operator has disabled the account, so no token is issued for it
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >
        An access token from `POST /api-key/token`. An organization token lasts one hour and has no refresh token; a personal token can be refreshed.

  schemas:
    AuthorizationServerMetadata:
      type: object
      required:
        - issuer
        - authorization_endpoint
        - token_endpoint
        - registration_endpoint
        - jwks_uri
        - scopes_supported
        - response_types_supported
        - grant_types_supported
        - code_challenge_methods_supported
        - token_endpoint_auth_methods_supported
      properties:
        issuer:
          type: string
          format: uri
          description: Equals the origin this document is served from.
        authorization_endpoint:
          type: string
          format: uri
        token_endpoint:
          type: string
          format: uri
        registration_endpoint:
          type: string
          format: uri
          description: Dynamic client registration (RFC 7591).
        jwks_uri:
          type: string
          format: uri
        scopes_supported:
          type: array
          items:
            type: string
        response_types_supported:
          type: array
          items:
            type: string
        grant_types_supported:
          type: array
          items:
            type: string
        code_challenge_methods_supported:
          type: array
          items:
            type: string
          description: S256 only; OAuth 2.1 drops "plain".
        token_endpoint_auth_methods_supported:
          type: array
          items:
            type: string
        resources_supported:
          type: array
          items:
            type: string
            format: uri
          description: RFC 8707 resource identifiers tokens may be minted for.

    AuthorizeClientResponse:
      type: object
      required:
        - client_id
        - client_name
        - redirect_host
        - scopes
        - vendor
        - verification
        - dynamically_registered
      properties:
        client_id:
          type: string
        client_name:
          type: string
          description: Always the client's own claim; the callback host is not.
        redirect_host:
          type: string
          description: Host of the callback this grant would be returned to.
        scopes:
          type: array
          items:
            type: string
        vendor:
          type: string
          description: The allowlist family whose rule admitted this client.
        verification:
          type: string
          enum: [vendor, local]
          description: |
            What the authorization server can vouch for, based on where the
            grant is delivered rather than on the name. `vendor` — the callback
            belongs to a recognised host, so only that vendor can receive the
            code. `local` — a loopback callback, so a program on the user's own
            machine, which cannot be identified further.
        dynamically_registered:
          type: boolean
          description: |
            True for a self-registered client, whose name is its own unvetted
            claim; the consent screen labels the name accordingly.

    ConsentGrantResponse:
      type: object
      required:
        - client_id
        - client_name
        - vendor
        - scopes
        - granted_at
        - verification
        - dynamically_registered
      properties:
        client_id:
          type: string
        client_name:
          type: string
        vendor:
          type: string
        scopes:
          type: array
          items:
            type: string
        granted_at:
          type: string
          format: date-time
        last_used_at:
          type: string
          format: date-time
          nullable: true
        verification:
          type: string
          enum: [vendor, local]
        dynamically_registered:
          type: boolean

    ConsentRequest:
      type: object
      required:
        - client_id
        - redirect_uri
        - response_type
        - code_challenge
        - code_challenge_method
        - resource
      properties:
        approved:
          type: boolean
          description: False returns the client to its redirect with access_denied.
        client_id:
          type: string
        redirect_uri:
          type: string
          format: uri
        response_type:
          type: string
          enum: [code]
        scope:
          type: string
        state:
          type: string
        code_challenge:
          type: string
        code_challenge_method:
          type: string
          enum: [S256]
        resource:
          type: string
          format: uri

    ConsentResponse:
      type: object
      required:
        - redirect_to
      properties:
        redirect_to:
          type: string
          format: uri
          description: Where the browser should go next, approved or denied.

    OAuthTokenResponse:
      type: object
      required:
        - access_token
        - token_type
        - expires_in
        - scope
      properties:
        access_token:
          type: string
          description: Audience-bound to the resource named in the authorize request.
        token_type:
          type: string
          enum: [Bearer]
        expires_in:
          type: integer
          format: int64
          description: Seconds until the access token expires.
        refresh_token:
          type: string
          description: Opaque and single-use; each refresh response replaces it.
        scope:
          type: string
          description: Space-delimited scopes the grant carries.

    RegisterOAuthClientRequest:
      type: object
      required:
        - redirect_uris
      properties:
        redirect_uris:
          type: array
          minItems: 1
          items:
            type: string
            format: uri
          description: |
            Exact callback URLs. Matched byte-for-byte at /oauth/authorize,
            except for loopback, where the port is ignored (RFC 8252 7.3).
            Must be https outside loopback, and carry no fragment or userinfo.
          example:
            - https://claude.ai/api/mcp/auth_callback
        client_name:
          type: string
          maxLength: 100
          description: |
            Self-asserted; shown on the consent screen as unverified. Refused
            with a 400 if it contains links, domain names, < or >, or control
            characters.
          example: Claude
        client_uri:
          type: string
          format: uri
        scope:
          type: string
          description: Space-delimited. Defaults to every supported scope when omitted.
          example: mcp:read mcp:trade
        grant_types:
          type: array
          items:
            type: string
            enum: [authorization_code, refresh_token]
        response_types:
          type: array
          items:
            type: string
            enum: [code]
        token_endpoint_auth_method:
          type: string
          enum: [none]
          description: Only public clients are supported.

    RegisterOAuthClientResponse:
      type: object
      required:
        - client_id
        - client_id_issued_at
        - redirect_uris
        - scope
        - grant_types
        - response_types
        - token_endpoint_auth_method
      properties:
        client_id:
          type: string
        client_id_issued_at:
          type: integer
          format: int64
          description: Seconds since the epoch.
        redirect_uris:
          type: array
          items:
            type: string
            format: uri
        client_name:
          type: string
        client_uri:
          type: string
        scope:
          type: string
        grant_types:
          type: array
          items:
            type: string
        response_types:
          type: array
          items:
            type: string
        token_endpoint_auth_method:
          type: string

    OAuthError:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: RFC 6749 5.2 error code, which clients branch on.
          enum:
            - invalid_request
            - invalid_client
            - invalid_grant
            - invalid_scope
            - unauthorized_client
            - unsupported_grant_type
            - access_denied
            - server_error
            - invalid_redirect_uri
            - invalid_client_metadata
        error_description:
          type: string

    Error:
      type: object
      description: Shared API error envelope
      required:
        - type
        - message
        - request_id
      properties:
        type:
          type: string
          description: Closed error category fixing the HTTP status
          enum:
            - invalid_argument
            - unauthenticated
            - permission_denied
            - not_found
            - method_not_allowed
            - conflict
            - failed_precondition
            - resource_exhausted
            - unavailable
            - internal
        code:
          type: string
          description: >-
            Specific error condition from the fleet code registry. Extensible: clients MUST tolerate values not listed here and fall back to type-based handling. Omitted when no code applies.
        message:
          type: string
          description: Human-readable description of the failure
        metadata:
          type: object
          description: >-
            Machine-readable context scoped to `code`; values are always strings. Which keys appear is determined by `code`.
          additionalProperties:
            type: string
        field_violations:
          type: array
          description: >-
            Per-field rejections, present on `invalid_argument` when the request failed field validation.
          items:
            type: object
            required:
              - field
              - message
            properties:
              field:
                type: string
                description: Dotted path to the offending field, as the client sent it
              message:
                type: string
                description: Human-readable reason the field was rejected
        request_id:
          type: string
          description: Identifier of the request that produced the error

    AccessTokensResponse:
      type: object
      required:
        - access_token
        - refresh_token
        - expires_in
        - token_type
      properties:
        access_token:
          type: string
          description: JWT access token
        refresh_token:
          type: string
          description: JWT refresh token
        expires_in:
          type: string
          format: date-time
          description: Access token expiration timestamp
        token_type:
          type: string
          description: Token type (always "Bearer")
          example: Bearer
        device_token:
          type: string
          description: >-
            Marks this client as signed in to the inbox by email; send it back as `X-Device-Token`. Present only on an email sign-in.
        turnkey_session:
          $ref: "#/components/schemas/TurnkeySession"

    TurnkeySession:
      type: object
      description: A Turnkey session on the public key a provider sign-in sent. Absent when none was asked for or none could be issued.
      required:
        - expires_at
      properties:
        expires_at:
          type: integer
          format: int64
          description: Session expiry, unix seconds

    OrganizationTokenResponse:
      type: object
      description: >
        Returned for an organization key. The access token lasts one hour and carries the organization's id in its `tm.organization_id` claim. There is no refresh token, so mint a new one from the key before it expires.
      required:
        - access_token
        - token_type
        - expires_in
      properties:
        access_token:
          type: string
          description: JWT access token
        token_type:
          type: string
          description: Token type (always "Bearer")
          example: Bearer
        expires_in:
          type: string
          format: date-time
          description: Access token expiration timestamp

    JWKSResponse:
      type: object
      required:
        - keys
      properties:
        keys:
          type: array
          items:
            $ref: "#/components/schemas/JWK"
          description: Array of JSON Web Keys

    JWK:
      type: object
      required:
        - kty
        - kid
        - use
        - alg
      properties:
        kty:
          type: string
          description: Key type
          example: RSA
        kid:
          type: string
          description: Key ID
        use:
          type: string
          description: Key use (sig for signature)
          example: sig
        alg:
          type: string
          description: Algorithm
          example: RS256
        n:
          type: string
          description: RSA modulus (base64url encoded)
        e:
          type: string
          description: RSA exponent (base64url encoded)

    RefreshTokenRequest:
      type: object
      required:
        - refresh_token
      properties:
        refresh_token:
          type: string
          description: The refresh token to exchange

    APIKeyTokenExchangeRequest:
      type: object
      required:
        - key_id
        - timestamp
        - signature
      properties:
        key_id:
          type: string
          format: uuid
          description: The API key ID
        timestamp:
          type: integer
          format: int64
          description: Current Unix timestamp (must be within ±30s of server time)
        signature:
          type: string
          description: Base64url-encoded ECDSA P-256 signature of `{key_id}.{timestamp}`
