openapi: 3.1.0
info:
  title: Fox Login Management API
  version: "1.0.0"
  description: |
    Everything a tenant can do in the dashboard, it can do with this API:
    create and delete applications, find, export and erase users, set labels,
    read event logs and manage webhooks.

    **Regions.** Management requests (this API) go to one base URL,
    `https://api.foxlogin.app/v1`, in Germany. End-user sign-in traffic
    (sign-up, sign-in, codes, Google sign-in, token refresh, sign-out) goes
    from the Fox Login SDKs and the user's browser directly to the user's
    region host (`eu.auth.foxlogin.app`, `tr.auth.foxlogin.app`); tenants
    never pick a host. Personal data is
    stored in the region assigned to the user's country (EU or TR at launch;
    all other countries are stored in EU). IDs carry the region as a hint:
    `usr_tr_8f2c91a7` lives in TR. Every user object includes `region`.
    Each application is single-region at launch: all its users are stored
    in the application's `region`.

    **Session tokens.** End-user session tokens are JWTs signed with
    EdDSA (Ed25519) by the user's region. Verify them locally with the keys
    from `GET /.well-known/jwks.json`. Claims are described in the
    `SessionTokenClaims` schema: `sub` (user ID), `rgn` (region), `app`,
    `labels`, `iat`, `exp` (short lifetime, for example 10 minutes) and
    `iss`.

    **Errors.** Every 4xx and 5xx response uses one envelope (`Error`):
    `{ "error": { "code", "message", "region", "retryable", "details" } }`.
    When a region cannot answer, the response is `503 region_unavailable`
    with `Retry-After`.

    **Authentication.** Send one of these keys as a Bearer token
    (`Authorization: Bearer …`). Each endpoint lists the scope it needs in
    `x-scopes`.

    | Key | Format | Reaches | Scopes |
    | --- | --- | --- | --- |
    | Secret key | `sk_live_eu_…`, `sk_live_tr_…` | its own application only | from the key's role |
    | Organization API key | `fk_live_…` | every application of the organization, and creating applications | the key's scopes |

    Use a secret key when your server works with one application. Every
    application gets one secret key with the `admin` role when it is
    created, and you can create more and give each one a role:

    | Role | Label | Scopes |
    | --- | --- | --- |
    | `admin` | Full access | applications:read, applications:write, users:read, users:write, events:read |
    | `editor` | Read and write users | applications:read, users:read, users:write, events:read |
    | `viewer` | Read only | applications:read, users:read, events:read |

    A secret key gets `404 not_found` for every other application and
    `403 secret_key_not_allowed` on `POST /applications` and the
    `/api_keys` endpoints. Keep it on your server, for example in the
    `FOXLOGIN_SECRET_KEY` environment variable. The publishable key
    (`pk_live_…`) does not work here; it only identifies the application
    to the End-user API.

    **Rate limits.** 100 requests/second per key. `429` responses include
    `Retry-After`.

    **Store only the user ID.** You do not need to copy email addresses,
    names or phone numbers into your own database. Save the Fox Login user
    ID (`usr_tr_8f2c91a7`) next to your own records. When you need people,
    ask us with a filter, for example "name contains `a` and email contains
    `b`", using `POST /applications/{app_id}/users/search`. When you need
    to show data for IDs you already have, send those IDs in `filter.ids`
    and ask only for the fields you will display. Personal data then stays
    in its region and you have nothing to erase when a user asks to be
    forgotten.
servers:
  - url: https://api.foxlogin.app/v1
security:
  - secretKey: []
  - tenantKey: []
tags:
  - name: Applications
  - name: Secret keys
    description: |
      Secret keys (`sk_live_eu_…`, `sk_live_tr_…`) let your server call this
      API for one application. One key is enough. You can also create
      several keys, for example one per server or job, and give each the
      role it needs:

      | Role | Label | Scopes |
      | --- | --- | --- |
      | `admin` | Full access | applications:read, applications:write, users:read, users:write, events:read |
      | `editor` | Read and write users | applications:read, users:read, users:write, events:read |
      | `viewer` | Read only | applications:read, users:read, events:read |

      `applications:write` on a secret key reaches only its own
      application: its settings (`PATCH /applications/{app_id}`) and its
      webhooks. No role has `keys:write`, so only
      dashboard owners and admins, or an organization API key with
      `keys:write`, create and revoke secret keys. The creator needs every
      scope of the role it gives. The full key is shown once, when it is
      created; only its SHA-256 hash is stored.
  - name: Users
    description: |
      Keep the user ID in your system, not the user's personal data.

      | You want to | Call |
      | --- | --- |
      | Find people by name, email, phone, label, region, status or date | `POST /users/search` with a `filter` |
      | Show names or emails for IDs you already store | `POST /users/search` with `filter.ids` and `fields` |
      | Read one user | `GET /users/{user_id}?fields=…` |
      | Export everything for a data access request | `GET /users/{user_id}/export` |

      Search results contain only `id` and `region` unless you ask for more
      with `fields`.
  - name: Labels
  - name: Logs & webhooks
  - name: Jobs
  - name: Keys
    description: Public keys for verifying session tokens.
  - name: Dashboard
    description: |
      Used by the Fox Login dashboard itself, not by tenant backends: who
      is signed in, their tenants, and organization API keys.

      Authenticate with a dashboard session token (`Authorization: Bearer`,
      an end-user session token of the dashboard's own Fox Login
      application) instead of a tenant API key. `GET /me` and
      `POST /me/tenants` need only that token. Every other Dashboard and
      Management endpoint also needs `X-Fox-Tenant: <tenant_id>`; access
      then follows the signed-in person's role in that tenant:

      | Role | Scopes |
      | --- | --- |
      | owner, admin | applications:read, applications:write, users:read, users:write, events:read, keys:write |
      | developer | applications:read, applications:write, users:read, users:write, events:read |
      | (any other member) "viewer" | applications:read, users:read, events:read |
  - name: End-user API (SDK)
    description: |
      Called by the Fox Login SDKs and hosted pages directly from the
      user's device or browser — never through `api.foxlogin.app` and
      never with a tenant API key. Authenticate with the application's
      publishable key (`X-Fox-Publishable-Key`); after sign-in, the MFA
      and sign-out endpoints take the session's access or refresh token
      instead.

      Served by each region host (`https://eu.auth.foxlogin.app`,
      `https://tr.auth.foxlogin.app`); the SDK calls the host of the
      application's region. `/internal/v1/*` is a separate, gateway-only
      API on the same hosts and is not part of this surface.

      Responses never reveal whether an email address has an account:
      `sign_up` and the two code-request endpoints always answer `202`.

      Google sign-in is a browser redirect flow, so its first step takes
      the publishable key as a query parameter: send the browser to
      `GET /v1/oauth/google/start`, and Fox Login brings it back to one of
      the application's `redirect_urls` with a one-time `fox_code`, which
      `POST /v1/client/oauth/token` exchanges for a session. The SDKs have
      no Google method yet; call these endpoints directly.

paths:
  /applications:
    get:
      tags: [Applications]
      summary: List applications
      description: "Up to 100 applications of the tenant, newest first. There is no pagination yet (no `has_more`, no cursor); a tenant with more than 100 will not see the rest. With a secret key, `data` holds only the key's own application."
      x-scopes: [applications:read]
      responses:
        "200":
          description: Applications of the tenant
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { type: array, items: { $ref: "#/components/schemas/Application" } }
        "401": { $ref: "#/components/responses/Unauthorized" }
    post:
      tags: [Applications]
      summary: Create an application
      description: |
        Creates a new, separate login with its own users, a publishable
        key and a first secret key. The response's `secret_key` holds that
        key (name `Default`, role `admin`); the full `key` appears only in
        this response, so store it on your server right away.

        The body takes no redirect URLs or provider settings; set them
        afterwards with `PATCH /applications/{app_id}`. Google sign-in is
        on by default (`providers.google.enabled: true`) and works once the
        application has at least one redirect URL.

        `region` is required and cannot be changed later (`PATCH` answers
        `422 region_immutable`): all end users of the application are
        stored in that region. Pick the region of your users' country (TR
        for Turkey, EU for everyone else at launch).

        Needs an organization API key or a dashboard session. The caller
        receives the new application's `admin` secret key, so it needs all
        of that role's scopes (`applications:read`, `applications:write`,
        `users:read`, `users:write`, `events:read`), or it gets
        `403 missing_scope`. A secret key gets
        `403 secret_key_not_allowed`.
      x-scopes: [applications:write]
      security:
        - tenantKey: []
        - dashboardSession: []
      parameters:
        - $ref: "#/components/parameters/TenantHeader"
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ApplicationCreateInput" }
            example:
              name: Anka Market Seller
              region: TR
              sector: ecommerce
              user_countries: [TR]
      responses:
        "201":
          description: Created. `secret_key.key` is returned only once.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ApplicationWithKeys" }
              example:
                id: app_8f2c91a7
                name: Anka Market Seller
                region: TR
                multi_region: false
                block: west
                sector: ecommerce
                user_countries: [TR]
                country_restriction: { mode: all, countries: [] }
                redirect_urls: []
                providers: { google: { enabled: true, mode: platform } }
                publishable_key: pk_live_tr_Xk2m9wQe4Rt7Yu1Io0Pa3Sd6Fg8Hj5Kl2Zx4Cv7Bn1M
                created_at: "2026-12-02T09:00:00.123456Z"
                secret_key:
                  id: key_5d1e9a20
                  name: Default
                  role: admin
                  prefix: sk_live_tr_Ab3d
                  key: sk_live_tr_Ab3dE5fG7hJ9kL1mN3pQ5rS7tU9vW1xY3zA5bC7dE9f
                  created_at: "2026-12-02T09:00:00Z"
                  created_by: null
                  last_used_at: null
        "400":
          description: "`invalid_name` (1-100 characters), `invalid_country_restriction` (`mode` must be `all` or `only_listed`) or `invalid_country` (not an ISO 3166-1 alpha-2 code, in `country_restriction.countries` or `user_countries`)."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "503":
          description: "`region_unavailable`: the application is not created if its region cannot be told about it."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /applications/{app_id}:
    parameters:
      - $ref: "#/components/parameters/AppId"
    get:
      tags: [Applications]
      summary: Get an application
      description: A secret key gets `404 not_found` for every application but its own.
      x-scopes: [applications:read]
      responses:
        "200":
          description: The application
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Application" }
        "404": { $ref: "#/components/responses/NotFound" }
    patch:
      tags: [Applications]
      summary: Update an application
      description: |
        Changes the name, the redirect URLs, the country restriction or
        Google sign-in. Send only the fields you change; the others keep
        their value. `redirect_urls` and `country_restriction` replace the
        whole stored value, so send the complete list every time.

        `region` cannot be changed. Sending the current region is accepted;
        any other value answers `422 region_immutable`. Fields this
        endpoint does not know, such as `sector` and `user_countries`, are
        ignored.

        **Redirect URLs.** Google sign-in sends users back only to a URL on
        this list, and the `redirect_uri` of `GET /v1/oauth/google/start`
        must match an entry character for character: scheme, host, port,
        path and query. There are no wildcards. Each URL uses `https`;
        `http` is allowed only for `localhost`, `127.0.0.1` and `[::1]`,
        for local development. A URL has a host, no user name or password,
        no `#`, `*` or spaces, and at most 500 characters. An application
        has at most 20; duplicates are dropped.

        The application's region is told about the change before it is
        saved. If the region cannot answer, nothing changes and the
        response is `503 region_unavailable`.

        A secret key can update only its own application; of the secret
        key roles, only `admin` has `applications:write`.
      x-scopes: [applications:write]
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ApplicationUpdateInput" }
            example:
              redirect_urls: ["https://anka.io/auth/callback", "http://localhost:3000/auth/callback"]
              providers: { google: { enabled: true } }
      responses:
        "200":
          description: The updated application
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Application" }
              example:
                id: app_8f2c91a7
                name: Anka Market
                region: EU
                multi_region: false
                block: west
                sector: ecommerce
                user_countries: []
                country_restriction: { mode: all, countries: [] }
                redirect_urls: ["https://anka.io/auth/callback", "http://localhost:3000/auth/callback"]
                providers: { google: { enabled: true, mode: platform } }
                publishable_key: pk_live_eu_Xk2m9wQe4Rt7Yu1Io0Pa3Sd6Fg8Hj5Kl2Zx4Cv7Bn1M
                created_at: "2026-12-02T09:00:00.123456Z"
        "400":
          description: "`invalid_redirect_url` (the message names the URL and the rule it breaks), `too_many_redirect_urls` (more than 20), `invalid_name` (1-100 characters), `invalid_country_restriction` (`mode` must be `all` or `only_listed`), `invalid_country` (not an ISO 3166-1 alpha-2 code) or `invalid_body`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
              example:
                error: { code: invalid_redirect_url, message: "http://anka.io/cb: the redirect URL must use https (http is allowed only for localhost).", region: null, retryable: false, details: {} }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }
        "422":
          description: "`region_immutable`: `region` differs from the application's region."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
              example:
                error: { code: region_immutable, message: The region of an application cannot be changed., region: null, retryable: false, details: {} }
        "503": { $ref: "#/components/responses/RegionUnavailable" }
    delete:
      tags: [Applications]
      summary: Delete an application
      description: |
        Not available yet. Would disable sign-in immediately and erase
        users of the application in their regions after a 7-day undo
        window, returning a job.
      x-scopes: [applications:delete]
      x-availability: planned
      responses:
        "202":
          description: Deletion scheduled
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Job" }

  /applications/{app_id}/providers/{provider}:
    parameters:
      - $ref: "#/components/parameters/AppId"
      - name: provider
        in: path
        required: true
        schema: { type: string, enum: [google, apple, github, microsoft] }
    get:
      tags: [Applications]
      summary: Get a social login provider
      description: |
        Not available yet. Google sign-in works today with Fox Login's own
        Google app: read it from `providers.google` on the application and
        turn it on or off with `PATCH /applications/{app_id}`. This
        endpoint, for using your own Google app and for Apple, GitHub and
        Microsoft, is planned.
      x-scopes: [applications:read]
      x-availability: planned
      responses:
        "200":
          description: Provider settings (secrets are masked)
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Provider" }
    put:
      tags: [Applications]
      summary: Configure a social login provider
      description: |
        Not available yet. `mode: platform` uses Fox Login's own app (no
        setup, users see "Fox Login"); Google sign-in already works this
        way and is turned on or off with `PATCH /applications/{app_id}`.
        `mode: custom` would use the tenant's own app and show its name.
        Apple, GitHub and Microsoft are planned. Switching Apple between modes
        changes Apple user IDs: affected users would be emailed and asked to
        link their account once; progress would be in `apple_relink`.
      x-scopes: [applications:write]
      x-availability: planned
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ProviderInput" }
      responses:
        "200":
          description: Updated provider
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Provider" }

  /applications/{app_id}/users:
    parameters:
      - $ref: "#/components/parameters/AppId"
    get:
      tags: [Users]
      summary: List users
      description: |
        Users of the application, newest first, from its region (MVP rule:
        applications are single-region). If the region does not answer,
        `data` is empty, `partial` is `true` and the region is listed in
        `regions_unavailable` — this is not a `503`, so always check
        `partial`.
      x-scopes: [users:read]
      parameters:
        - { name: email, in: query, description: "Exact match, normalized (case/accent-insensitive).", schema: { type: string } }
        - { name: limit, in: query, schema: { type: integer, default: 50, minimum: 1, maximum: 100 } }
        - { name: cursor, in: query, description: "`next_cursor` from the previous page", schema: { type: string } }
      responses:
        "200":
          description: Users
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { type: array, items: { $ref: "#/components/schemas/User" } }
                  next_cursor: { type: [string, "null"] }
                  regions_unavailable: { $ref: "#/components/schemas/RegionsUnavailable" }
                  partial: { $ref: "#/components/schemas/Partial" }
        "503": { $ref: "#/components/responses/RegionUnavailable" }
    post:
      tags: [Users]
      summary: Create a user
      description: |
        The user is stored in the region of `country`. `country` is required.

        MVP rule: applications are single-region. Users from any country are
        stored in the application's region, and the tenant is responsible for
        accepting users from countries whose data rules require something else.
        If the application has `country_restriction.mode: only_listed`, a
        country that is not listed returns `422 country_not_allowed`. An email
        that already exists in
        the application returns `409 email_exists` with the existing user's
        ID in `error.details.user_id`. There is no `phone` field and no
        invite email; set a `password` directly or leave the account
        passwordless.
      x-scopes: [users:write]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [email, country]
              properties:
                email: { type: string, format: email }
                name: { type: string }
                country: { type: string, description: "ISO 3166-1 alpha-2. Decides the data region.", example: TR }
                labels: { $ref: "#/components/schemas/Labels" }
                password: { type: string, minLength: 8, maxLength: 256, description: Optional. Omit to create a passwordless account. }
                email_verified: { type: boolean, default: false }
      responses:
        "201":
          description: Created
          content:
            application/json:
              schema: { $ref: "#/components/schemas/User" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "409":
          description: "`email_exists`: the email already belongs to a user of this application."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
              example:
                error:
                  code: email_exists
                  message: A user with this email already exists in this application.
                  region: TR
                  retryable: false
                  details: { user_id: usr_tr_8f2c91a7 }
        "422": { $ref: "#/components/responses/CountryNotAllowed" }
        "503": { $ref: "#/components/responses/RegionUnavailable" }

  /applications/{app_id}/users/search:
    parameters:
      - $ref: "#/components/parameters/AppId"
    post:
      tags: [Users]
      summary: Search users with a filter
      x-availability: planned
      description: |
        Not available yet; use `GET /applications/{app_id}/users?email=…`
        for an exact-email lookup today. Find users by what you know about
        them, without storing their personal data yourself. Send a
        `filter`: every condition must match (AND). Put alternatives in
        `any` (OR).

        - Text conditions (`name`, `email`, `phone`) take one operator:
          `equals`, `contains`, `starts_with` or `ends_with`. Matching
          ignores case and accents.
        - `ids` looks up users you already know (max 100), for example to
          show names next to the IDs in your database.
        - Each region is searched where its data lives; the results are
          merged. Only the `fields` you ask for are returned. The default is
          `id` and `region`.
        - If a region does not answer, `partial` is `true` and the region is
          listed in `regions_unavailable`; retry later for complete results.
        - Every search is written to the event log as `users.searched`
          with the filter keys and the API key, so the tenant can audit it.
      x-scopes: [users:read]
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/UserSearchRequest" }
            examples:
              name_and_email:
                summary: Name contains "a" and email contains "b"
                value:
                  filter:
                    name: { contains: "a" }
                    email: { contains: "b" }
                  fields: [id, name, email]
                  limit: 50
              store_and_activity:
                summary: Active users of one store who signed in this month, in TR or EU
                value:
                  filter:
                    labels: { store: mavi-ev-tekstil }
                    status: [active]
                    region: [TR, EU]
                    last_sign_in_at: { gte: "2026-12-01T00:00:00Z" }
                  sort: -last_sign_in_at
              resolve_ids:
                summary: Show names for IDs you already store
                value:
                  filter:
                    ids: [usr_tr_312, usr_eu_9a41c2, usr_eu_77d0e1]
                  fields: [id, name]
              either_domain:
                summary: Email ends with one of two domains (OR)
                value:
                  filter:
                    any:
                      - email: { ends_with: "@maviev.com.tr" }
                      - email: { ends_with: "@anka.io" }
                  fields: [id, email]
      responses:
        "200":
          description: Matching users, with only the requested fields
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { type: array, items: { $ref: "#/components/schemas/User" } }
                  next_cursor: { type: [string, "null"] }
                  regions_searched: { type: array, items: { $ref: "#/components/schemas/Region" } }
                  regions_unavailable: { $ref: "#/components/schemas/RegionsUnavailable" }
                  partial: { $ref: "#/components/schemas/Partial" }
              example:
                data:
                  - { id: usr_tr_312, name: "Elif Kaya", email: "elif@maviev.com.tr" }
                  - { id: usr_eu_9a41c2, name: "Anna Bauer", email: "anna@bauer-web.de" }
                next_cursor: null
                regions_searched: [EU, TR]
                regions_unavailable: []
                partial: false
        "400":
          description: |
            Invalid filter, for example an unknown field or two operators in
            one text condition.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "503": { $ref: "#/components/responses/RegionUnavailable" }

  /applications/{app_id}/invitations:
    parameters:
      - $ref: "#/components/parameters/AppId"
    post:
      tags: [Users]
      summary: Invite a user with labels
      x-availability: planned
      description: |
        Not available yet. Would create an invite link. Labels in the
        invite would be set automatically when the user signs up (e.g. the
        store they belong to). Label groups set to "user picks" would
        still be shown on the sign-up page.

        `country` is required. MVP rule: the user is stored in the application's
        region; with `country_restriction.mode: only_listed`, an unlisted
        country returns `422 country_not_allowed`.
      x-scopes: [users:write]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [email, country]
              properties:
                email: { type: string, format: email }
                country: { type: string, description: "ISO 3166-1 alpha-2. Decides the data region.", example: TR }
                labels: { $ref: "#/components/schemas/Labels" }
                send_email: { type: boolean, default: true }
                expires_in_days: { type: integer, default: 7 }
      responses:
        "201":
          description: Invite created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id: { type: string }
                  url: { type: string, example: "https://auth.seller.anka.io/invite/inv_7Gk2" }
                  expires_at: { type: string, format: date-time }
        "400": { $ref: "#/components/responses/BadRequest" }
        "422": { $ref: "#/components/responses/CountryNotAllowed" }

  /applications/{app_id}/users/{user_id}:
    parameters:
      - $ref: "#/components/parameters/AppId"
      - $ref: "#/components/parameters/UserId"
    get:
      tags: [Users]
      summary: Get a user
      description: |
        Returns the full user object; there is no `fields` or `expand`
        filtering yet. `user_id` must belong to the application's region
        (its prefix, e.g. `usr_tr_...`, names the region) or this returns
        `404` without calling the region at all.
      x-scopes: [users:read]
      responses:
        "200":
          description: The user
          content:
            application/json:
              schema: { $ref: "#/components/schemas/User" }
        "404": { $ref: "#/components/responses/NotFound" }
        "503": { $ref: "#/components/responses/RegionUnavailable" }
    patch:
      tags: [Users]
      summary: Update a user
      description: Not available yet.
      x-scopes: [users:write]
      x-availability: planned
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string }
                email: { type: string, format: email }
                phone: { type: string }
                metadata: { type: object, additionalProperties: true }
      responses:
        "200":
          description: Updated user
          content:
            application/json:
              schema: { $ref: "#/components/schemas/User" }
    delete:
      tags: [Users]
      summary: Delete user data
      description: |
        Not available yet. Would erase the user in their region: profile,
        password, phone, 2FA factors, sessions, labels and events; sign
        them out on all devices; purge backups within 30 days; send
        `user.erased`. Cannot be undone.
      x-scopes: [users:delete]
      x-availability: planned
      parameters:
        - name: erase
          in: query
          schema: { type: string, enum: [all, account], default: all }
          description: "`account` keeps anonymous events for statistics."
        - name: notify
          in: query
          schema: { type: boolean, default: false }
      responses:
        "202":
          description: Erasure job queued
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Job" }

  /applications/{app_id}/users/{user_id}/export:
    parameters:
      - $ref: "#/components/parameters/AppId"
      - $ref: "#/components/parameters/UserId"
    get:
      tags: [Users]
      summary: Export all user data
      description: Not available yet. Would return everything stored about the user, as one JSON (KVKK / GDPR access request).
      x-scopes: [users:read_full]
      x-availability: planned
      responses:
        "200":
          description: Full export
          content:
            application/json:
              schema: { $ref: "#/components/schemas/UserExport" }

  /applications/{app_id}/users/{user_id}/email/verify:
    parameters:
      - $ref: "#/components/parameters/AppId"
      - $ref: "#/components/parameters/UserId"
    post:
      tags: [Users]
      summary: Mark an email as verified
      description: |
        Not available yet. `email_verification: external` and its webhook
        `email.verification_requested` are not implemented either; today
        Fox Login always sends its own verification code email.
      x-scopes: [users:write]
      x-availability: planned
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                verified_at: { type: string, format: date-time }
                method: { type: string, enum: [code, link, manual] }
      responses:
        "200":
          description: Verified
          content:
            application/json:
              schema:
                type: object
                properties:
                  email_verified: { type: boolean }

  /applications/{app_id}/users/{user_id}/labels:
    parameters:
      - $ref: "#/components/parameters/AppId"
      - $ref: "#/components/parameters/UserId"
    put:
      tags: [Users]
      summary: Set labels
      description: Not available yet. Would replace the user's labels (which already appear in the session token under `labels`, and can be set with `POST /applications/{app_id}/users` today).
      x-scopes: [labels:write]
      x-availability: planned
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/Labels" }
      responses:
        "200":
          description: Labels after the change
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Labels" }

  /applications/{app_id}/users/{user_id}/lock:
    parameters:
      - $ref: "#/components/parameters/AppId"
      - $ref: "#/components/parameters/UserId"
    post:
      tags: [Users]
      summary: Lock or unlock a user
      description: Not available yet.
      x-scopes: [users:lock]
      x-availability: planned
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                locked: { type: boolean }
                revoke_sessions: { type: boolean, default: true }
      responses:
        "200":
          description: User
          content:
            application/json:
              schema: { $ref: "#/components/schemas/User" }

  /applications/{app_id}/users/{user_id}/move:
    parameters:
      - $ref: "#/components/parameters/AppId"
      - $ref: "#/components/parameters/UserId"
    post:
      tags: [Users]
      summary: Move a user to another country
      description: |
        Not in the first release.

        Moves the user to the region of the new country. The user ID does not
        change. All sessions are ended and refresh tokens are revoked when
        the move switches over; access tokens already issued expire on their
        own (short lifetime). The old region keeps a forwarding record with
        no personal data, so requests that still reach it get `409
        user_moved` with the new region. Sends `user.region_changed`.

        Only the tenant can move a user; end users cannot change their own
        country.
      x-scopes: [users:write]
      x-availability: next-release
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [country]
              properties:
                country: { type: string, description: "ISO 3166-1 alpha-2 of the new country", example: DE }
      responses:
        "202":
          description: Move job queued
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Job" }
              example: { job_id: job_4m7q, type: user_move, status: queued, region: EU }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: "`user_moved`: the user is already in another region (`error.region` names it)."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
              example:
                error:
                  code: user_moved
                  message: This user has moved to another region.
                  region: EU
                  retryable: false
                  details: { user_id: usr_tr_8f2c91a7 }
        "422":
          description: "`method_not_available`: user moves are not available yet."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "503": { $ref: "#/components/responses/RegionUnavailable" }

  /applications/{app_id}/label-groups:
    parameters:
      - $ref: "#/components/parameters/AppId"
    get:
      tags: [Labels]
      summary: List label groups
      description: Not available yet. The `labels` on a user are a free-form map today (set at creation); there is no label-group schema or sign-up UI for it yet.
      x-scopes: [applications:read]
      x-availability: planned
      responses:
        "200":
          description: Label groups
          content:
            application/json:
              schema: { type: array, items: { $ref: "#/components/schemas/LabelGroup" } }
    post:
      tags: [Labels]
      summary: Create a label group
      description: Not available yet.
      x-scopes: [labels:write]
      x-availability: planned
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/LabelGroup" }
      responses:
        "201":
          description: Created
          content:
            application/json:
              schema: { $ref: "#/components/schemas/LabelGroup" }

  /applications/{app_id}/events:
    parameters:
      - $ref: "#/components/parameters/AppId"
    get:
      tags: [Logs & webhooks]
      summary: List events
      x-scopes: [events:read]
      parameters:
        - { name: user_id, in: query, description: Only this user's events., schema: { type: string } }
        - { name: limit, in: query, schema: { type: integer, default: 50, minimum: 1, maximum: 100 } }
        - { name: cursor, in: query, description: "`next_cursor` from the previous page", schema: { type: string } }
      description: |
        The application's sign-up and sign-in events, newest first, from
        its region. There is no `type` or `since` filter yet — filter
        client-side, or by `user_id`. If the region does not answer,
        `data` is empty, `partial` is `true` and the region is listed in
        `regions_unavailable` — this is not a `503`, so always check
        `partial`.
      responses:
        "200":
          description: Events, newest first
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { type: array, items: { $ref: "#/components/schemas/Event" } }
                  next_cursor: { type: [string, "null"] }
                  regions_unavailable: { $ref: "#/components/schemas/RegionsUnavailable" }
                  partial: { $ref: "#/components/schemas/Partial" }
              example:
                data:
                  - { id: evt_123, type: sign_in.failed, user_id: usr_tr_8f2c91a7, ip: "203.0.113.4", created_at: "2026-12-02T09:14:00Z" }
                next_cursor: "eyJFVSI6ImV2dF85OCIsIlRSIjoiZXZ0XzEyMyJ9"
                regions_unavailable: []
                partial: false
        "503": { $ref: "#/components/responses/RegionUnavailable" }

  /applications/{app_id}/webhooks:
    parameters:
      - $ref: "#/components/parameters/AppId"
    get:
      tags: [Logs & webhooks]
      summary: List webhook endpoints
      x-scopes: [applications:read]
      responses:
        "200":
          description: Endpoints (without their secrets) and the subscribable event types
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { type: array, items: { $ref: "#/components/schemas/WebhookEndpoint" } }
                  event_types: { type: array, items: { type: string } }
    post:
      tags: [Logs & webhooks]
      summary: Create a webhook endpoint
      description: |
        At most 10 endpoints per application (`422 webhook_limit`). The
        signing secret is returned only in this response; store it, it
        cannot be read back. See the `WebhookDelivery` schema for the
        delivery shape and headers.
      x-scopes: [applications:write]
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/WebhookEndpointInput" }
      responses:
        "201":
          description: Created. The secret is returned only once.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/WebhookEndpointWithSecret" }
        "400":
          description: "`invalid_webhook_url` or `invalid_events`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "422":
          description: "`webhook_limit`: the application already has 10 endpoints."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /applications/{app_id}/webhooks/{endpoint_id}:
    parameters:
      - $ref: "#/components/parameters/AppId"
      - name: endpoint_id
        in: path
        required: true
        schema: { type: string, example: whe_8f2c91a7 }
    delete:
      tags: [Logs & webhooks]
      summary: Delete a webhook endpoint
      x-scopes: [applications:write]
      responses:
        "204": { description: Deleted }
        "404": { $ref: "#/components/responses/NotFound" }

  /applications/{app_id}/secret_keys:
    parameters:
      - $ref: "#/components/parameters/AppId"
    get:
      tags: [Secret keys]
      summary: List secret keys
      operationId: listSecretKeys
      description: |
        The application's secret keys, newest first. Revoked keys stay in
        the list with `revoked_at` set. The full key is never shown again;
        `prefix` tells keys apart. `last_used_at` is updated at most once a
        minute.

        A secret key can list its own application's keys only when its
        role is `admin`. `editor` and `viewer` keys get `403 missing_scope`.
      x-scopes: [applications:read]
      security:
        - secretKey: []
        - tenantKey: []
        - dashboardSession: []
      parameters:
        - $ref: "#/components/parameters/TenantHeader"
      responses:
        "200":
          description: Secret keys of the application, newest first
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { type: array, items: { $ref: "#/components/schemas/SecretKey" } }
              example:
                data:
                  - { id: key_3b7e10c2, name: Billing worker, role: editor, prefix: sk_live_eu_Q9xT, created_at: "2026-12-02T10:20:00Z", created_by: usr_eu_8f2c91a7, last_used_at: "2026-12-02T11:02:13Z", revoked_at: null }
                  - { id: key_5d1e9a20, name: Default, role: admin, prefix: sk_live_eu_Ab3d, created_at: "2026-12-01T08:00:00Z", created_by: null, last_used_at: "2026-12-02T08:59:40Z", revoked_at: "2026-12-02T09:00:00Z" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }
    post:
      tags: [Secret keys]
      summary: Create a secret key
      operationId: createSecretKey
      description: |
        Creates another secret key for the application and returns it once,
        in `key`. Only its hash is stored, so save it right away. With one
        key per server or job, each gets the smallest role it needs and you
        can revoke one without changing the others.

        Needs `keys:write`: a dashboard owner or admin, or an organization
        API key with that scope. The caller also needs every scope of the
        role it gives, or it gets `403 missing_scope`. A secret key gets
        `403 secret_key_not_allowed`.
      x-scopes: [keys:write]
      security:
        - tenantKey: []
        - dashboardSession: []
      parameters:
        - $ref: "#/components/parameters/TenantHeader"
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/SecretKeyInput" }
            example: { name: Billing worker, role: editor }
      responses:
        "201":
          description: Created. The full `key` is returned only once.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SecretKeyWithKey" }
              example:
                id: key_3b7e10c2
                name: Billing worker
                role: editor
                prefix: sk_live_eu_Q9xT
                key: sk_live_eu_Q9xTa7Lm2Nb4Vc6Xz8Sd1Fg3Hj5Kl7Pq9Wr2Ey4Tu6I
                created_at: "2026-12-02T10:20:00Z"
                created_by: usr_eu_8f2c91a7
                last_used_at: null
        "400":
          description: "`invalid_role` (`role` must be `admin`, `editor` or `viewer`), `invalid_name` (more than 60 characters) or `invalid_body`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
              example:
                error: { code: invalid_role, message: "The role must be admin, editor or viewer.", region: null, retryable: false, details: {} }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }

  /applications/{app_id}/secret_keys/{key_id}:
    parameters:
      - $ref: "#/components/parameters/AppId"
      - name: key_id
        in: path
        required: true
        schema: { type: string, example: key_3b7e10c2 }
    delete:
      tags: [Secret keys]
      summary: Revoke a secret key
      operationId: revokeSecretKey
      description: |
        The key stops working at once; calls with it get
        `401 invalid_api_key`. It stays in the list with `revoked_at` set.
        Revoking a key that is already revoked answers `204` again. A key
        id of another application, or an organization API key id, answers
        `404 not_found`.

        Needs `keys:write`, like creating a key. A secret key gets
        `403 secret_key_not_allowed`.
      x-scopes: [keys:write]
      security:
        - tenantKey: []
        - dashboardSession: []
      parameters:
        - $ref: "#/components/parameters/TenantHeader"
      responses:
        "204": { description: Revoked }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }

  /jobs/{job_id}:
    get:
      tags: [Jobs]
      summary: Get a job
      description: |
        Not available yet. There is no job queue: application delete,
        user delete/export and user move (also not available yet) are
        the only operations that would produce one.
      x-scopes: [jobs:read]
      x-availability: planned
      parameters:
        - { name: job_id, in: path, required: true, schema: { type: string } }
      responses:
        "200":
          description: Job
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Job" }
        "404": { $ref: "#/components/responses/NotFound" }

  /me:
    get:
      tags: [Dashboard]
      summary: Get the signed-in dashboard person
      description: Needs a dashboard session token; no `X-Fox-Tenant` and no scope check.
      security:
        - dashboardSession: []
      responses:
        "200":
          description: The person and every tenant they are a member of
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Me" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404":
          description: "`not_found`: the dashboard is not configured on this gateway (`FOX_DASHBOARD_APP_ID` unset)."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /me/tenants:
    post:
      tags: [Dashboard]
      summary: Create a tenant
      description: |
        Self-serve: the signed-in person becomes the new tenant's `owner`.
        A person can own at most 5 tenants (`422 tenant_limit`).
      security:
        - dashboardSession: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name]
              properties:
                name: { type: string, minLength: 1, maxLength: 100 }
      responses:
        "201":
          description: Created; the caller is its owner
          content:
            application/json:
              schema:
                type: object
                properties:
                  id: { type: string, example: ten_8f2c91a7 }
                  name: { type: string }
                  role: { type: string, const: owner }
        "400": { $ref: "#/components/responses/BadRequest" }
        "422":
          description: "`tenant_limit`: the person already owns 5 tenants."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /api_keys:
    get:
      tags: [Dashboard]
      summary: List organization API keys
      description: |
        Organization API keys (`fk_live_…`) only. Application secret keys
        are listed per application with `GET /applications/{app_id}/secret_keys`.
        Includes revoked keys (with `revoked_at` set). Keys never show
        their secret again. Needs `keys:write`, not a separate
        `keys:read` — there is no read-only way to list keys; `developer`
        and viewer roles cannot. A secret key gets
        `403 secret_key_not_allowed`.
      x-scopes: [keys:write]
      security:
        - tenantKey: []
        - dashboardSession: []
      parameters:
        - $ref: "#/components/parameters/TenantHeader"
      responses:
        "200":
          description: Keys
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { type: array, items: { $ref: "#/components/schemas/TenantApiKey" } }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
    post:
      tags: [Dashboard]
      summary: Create an organization API key
      description: |
        The key is returned once, in `key`; only its hash and a
        12-character `prefix` are stored.

        Choose the key's scopes in `scopes`. Without `scopes` the key gets
        `applications:read`, `applications:write`, `users:read`,
        `users:write` and `events:read`. `keys:write` lets a key create and
        revoke keys, so a key gets it only when you list it in `scopes`.

        You can give only scopes you have yourself. Dashboard owners and
        admins have all six; an organization API key has the scopes it was
        created with. Asking for a scope you lack, the default set
        included, answers `403 missing_scope`. A secret key gets
        `403 secret_key_not_allowed`.
      x-scopes: [keys:write]
      security:
        - tenantKey: []
        - dashboardSession: []
      parameters:
        - $ref: "#/components/parameters/TenantHeader"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name]
              properties:
                name: { type: string, minLength: 1, maxLength: 60 }
                scopes:
                  type: array
                  minItems: 1
                  description: "Scopes of the new key. Duplicates are ignored; the response lists them in a fixed order. Omit for the default set, which never includes `keys:write`."
                  items: { $ref: "#/components/schemas/OrganizationScope" }
                  default: [applications:read, applications:write, users:read, users:write, events:read]
            example: { name: Provisioning, scopes: [applications:read, applications:write, users:read, users:write, events:read, keys:write] }
      responses:
        "201":
          description: Created. The secret `key` is returned only once.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/TenantApiKeyWithSecret" }
              example:
                id: key_7c4a2e91
                name: Provisioning
                key: fk_live_Rt5yU7iO9pA1sD3fG5hJ7kL9zX1cV3bN5mQ7wE9rT1y
                scopes: [applications:read, applications:write, users:read, users:write, events:read, keys:write]
        "400":
          description: "`invalid_name` (1-60 characters), `invalid_scope` (an unknown scope, or an empty `scopes` list) or `invalid_body`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
              example:
                error: { code: invalid_scope, message: "users:delete is not a scope. Use scopes from: applications:read, applications:write, users:read, users:write, events:read, keys:write.", region: null, retryable: false, details: {} }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }

  /api_keys/{key_id}:
    parameters:
      - name: key_id
        in: path
        required: true
        schema: { type: string, example: key_8f2c91a7 }
    delete:
      tags: [Dashboard]
      summary: Revoke an organization API key
      description: Only organization API keys. The id of an application secret key answers `404 not_found`; revoke it with `DELETE /applications/{app_id}/secret_keys/{key_id}`. A secret key gets `403 secret_key_not_allowed`.
      x-scopes: [keys:write]
      security:
        - tenantKey: []
        - dashboardSession: []
      parameters:
        - $ref: "#/components/parameters/TenantHeader"
      responses:
        "204": { description: Revoked }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }

  /.well-known/jwks.json:
    servers:
      - url: https://api.foxlogin.app
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    get:
      tags: [Keys]
      summary: Get the JSON Web Key Set
      description: |
        JSON Web Key Set for verifying session tokens. There is one key per
        region and version; `kid` is `<region>-v<N>`, for example `tr-v1`.
        Each region host serves its own keys at the same path, so token
        checks do not depend on Germany. Cache the response. New keys are
        published at least 24 hours before they are first used to sign.
        No API key is needed.
      security: []
      responses:
        "200":
          description: Key set
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Jwks" }
              example:
                keys:
                  - { kty: OKP, crv: Ed25519, x: "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo", kid: eu-v1, use: sig, alg: EdDSA }
                  - { kty: OKP, crv: Ed25519, x: "3p7bfXt9wbTTW2HC7OQ1Nz-DQ8hbeGdNrfx-FG-IK08", kid: tr-v1, use: sig, alg: EdDSA }

  /v1/client/sign_up:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    post:
      tags: [End-user API (SDK)]
      summary: Sign up
      security:
        - publishableKey: []
      description: |
        Always answers `202 verification_sent`, whether or not the email
        already has an account — an existing address gets an "you already
        have an account" email instead of a code, so the response cannot
        be used to probe for registered addresses. Rate-limited to 10
        sign-ups per minute per IP (`429 rate_limited`).
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/SignUpInput" }
      responses:
        "202":
          description: verification_sent
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Accepted" }
              example: { status: verification_sent }
        "400":
          description: "`invalid_email`, `weak_password` (8-256 characters) or `invalid_country`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "422": { $ref: "#/components/responses/CountryNotAllowed" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "503":
          description: "`busy`: too many sign-ins right now."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /v1/client/sign_up/verify:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    post:
      tags: [End-user API (SDK)]
      summary: Confirm the sign-up code and sign in
      security:
        - publishableKey: []
      description: |
        Creates the account on the first correct code and signs it in.
        Codes are six digits, valid 15 minutes, and allow 5 wrong
        attempts (`400 invalid_code` after that, or once expired).
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/VerifyCodeInput" }
      responses:
        "200":
          description: Signed in, or `mfa_required` if the account somehow already has TOTP on.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SignInResult" }
        "400":
          description: "`invalid_code`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /v1/client/sign_in:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    post:
      tags: [End-user API (SDK)]
      summary: Sign in with a password
      security:
        - publishableKey: []
      description: |
        Rate-limited to 10 attempts/minute per account and 30/minute per
        IP across accounts (credential stuffing). A wrong email or
        password, or an account that is not `active`, both answer the
        same `401 invalid_credentials` (an inactive account's status is
        never revealed).
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/SignInInput" }
      responses:
        "200":
          description: Signed in, or `mfa_required`
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SignInResult" }
        "401":
          description: "`invalid_credentials` or `missing_publishable_key`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /v1/client/sign_in/email_code:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    post:
      tags: [End-user API (SDK)]
      summary: "Passwordless sign-in, step 1: email a code"
      security:
        - publishableKey: []
      description: |
        Always answers `202 code_sent`, whether or not the account exists
        or is active. At most 3 codes per account per minute
        (`429 rate_limited`).
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/EmailInput" }
      responses:
        "202":
          description: code_sent
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Accepted" }
              example: { status: code_sent }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /v1/client/sign_in/email_code/verify:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    post:
      tags: [End-user API (SDK)]
      summary: "Passwordless sign-in, step 2: verify the code"
      security:
        - publishableKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/VerifyCodeInput" }
      responses:
        "200":
          description: Signed in, or `mfa_required`
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SignInResult" }
        "401":
          description: "`invalid_code`: the code is wrong or has expired, or the account does not exist or is not active. (Returned as 401, unlike the `400 invalid_code` of the other verify endpoints.)"
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /v1/oauth/google/start:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    get:
      tags: [End-user API (SDK)]
      summary: "Google sign-in, step 1: send the browser to Google"
      security: []
      description: |
        Open this URL in the user's browser with a link or
        `location.assign`, not with `fetch`. Fox Login checks the request
        and answers `303` with a redirect to Google's account chooser.
        Fox Login uses its own Google app, so users see "Fox Login" on
        Google's screen and there is nothing to set up at Google. Using
        your own Google app is planned.

        Call the host of the application's region, which the publishable
        key names: `pk_live_eu_…` → `eu.auth.foxlogin.app`. Google sign-in
        must be on for the application (`providers.google.enabled`, on by
        default), and `redirect_uri` must be one of its `redirect_urls`
        (see `PATCH /applications/{app_id}`).

        Google returns the browser to
        `https://<region>.auth.foxlogin.app/v1/oauth/google/callback`, the
        Return URL of Fox Login's Google app. You never call it and do not
        enter it anywhere. Fox Login exchanges Google's code (with PKCE),
        checks the ID token and sends the browser on to `redirect_uri`,
        adding these query parameters after any query the URL already has:

        | Parameters | When | Next step |
        | --- | --- | --- |
        | `fox_code` | An existing user (linked before, or matched by email), or a new user created with the `country` you passed. | `POST /v1/client/oauth/token` within 2 minutes |
        | `fox_status=country_required`, `fox_ticket` | A new user, and the start URL had no `country`. | Ask for the country, then `POST /v1/client/oauth/complete` within 15 minutes |
        | `fox_error` | The sign-in did not finish. | Show a message and offer to try again |

        Each comes with `state` when you sent one. `fox_error` is
        `access_denied` (the user cancelled at Google), `provider_error`
        (Google's answer could not be used), `email_not_verified` (Google
        has not verified the account's email), `account_locked` (the
        matching user is not active), `country_not_allowed` or
        `server_error`. Treat any other value like `provider_error`.

        A Google account signs in to the user it is linked to. A Google
        account seen for the first time is linked to the user of this
        application with the same email, which Google must have verified;
        that records `identity.linked` and marks the user's email verified.
        If there is no such user, a new one is created with
        `email_verified: true` and the name from Google. Users belong to
        one application, so the same Google account is a separate user in
        each application.

        Errors in this step are answered as JSON, not as a redirect,
        because they mean the start URL itself is wrong. At most 30 starts
        per minute per IP address (`429 rate_limited`). Each sign-in can
        return once, within 10 minutes. A late or repeated return gets Fox
        Login's own "This sign-in link has expired" page (`400`, HTML)
        instead of a redirect, because there is no trusted place to send
        the browser.
      parameters:
        - name: publishable_key
          in: query
          required: true
          description: The application's publishable key. It goes in the URL because a browser navigation cannot send the `X-Fox-Publishable-Key` header.
          schema: { type: string, example: pk_live_eu_Xk2m9wQe4Rt7Yu1Io0Pa3Sd6Fg8Hj5Kl2Zx4Cv7Bn1M }
        - name: redirect_uri
          in: query
          required: true
          description: Where the browser returns. Must equal one of the application's `redirect_urls` exactly.
          schema: { type: string, format: uri, example: "https://anka.io/auth/callback" }
        - name: state
          in: query
          description: Your own value, returned unchanged as `state` on `redirect_uri`. Use a random value kept in the browser session and compare it when the user returns. At most 512 characters.
          schema: { type: string, maxLength: 512 }
        - name: country
          in: query
          description: "ISO 3166-1 alpha-2 country for a new user, in any case. With it, a new user is created during the callback and you get `fox_code` at once; without it, a new user comes back with `fox_status=country_required`. It is checked against the country restriction at the start; existing users keep their country."
          schema: { type: string, example: TR }
      responses:
        "303":
          description: Redirect to Google.
          headers:
            Location:
              description: Google's authorization URL (OpenID Connect code flow with PKCE).
              schema: { type: string }
        "400":
          description: "`redirect_uri_not_allowed` (add the URL to the application's `redirect_urls` first), `invalid_state` (longer than 512 characters) or `invalid_country`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
              example:
                error: { code: redirect_uri_not_allowed, message: "Add this redirect_uri to the application's redirect URLs first.", region: null, retryable: false, details: {} }
        "401":
          description: "`invalid_publishable_key`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "422":
          description: "`provider_disabled` (Google sign-in is turned off for this application) or `country_not_allowed`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "503":
          description: "`provider_not_configured`: Google sign-in is not set up in this region. Retry after `Retry-After` seconds."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        default:
          description: Any other error, such as a `500`, uses the same error envelope.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /v1/client/oauth/token:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    post:
      tags: [End-user API (SDK)]
      summary: "Google sign-in, step 2: exchange the code for a session"
      security:
        - publishableKey: []
      description: |
        Exchanges the `fox_code` from the redirect for a session and
        answers like a password sign-in: a session, or `mfa_required` when
        the user has TOTP on (finish with `POST /v1/client/sign_in/mfa`).
        The code works once, for 2 minutes, and only with the publishable
        key of the application that started the sign-in. Records
        `user.signed_in` with `method: google`. Counts toward the limit of
        20 code checks per minute per IP address.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/OAuthCodeInput" }
      responses:
        "200":
          description: Signed in, or `mfa_required`
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SignInResult" }
        "400":
          description: "`invalid_code`: the code is wrong, used or expired, or the user is no longer active. Start the sign-in again."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
              example:
                error: { code: invalid_code, message: The sign-in link is wrong or has expired. Start again., region: null, retryable: false, details: {} }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /v1/client/oauth/complete:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    post:
      tags: [End-user API (SDK)]
      summary: "Google sign-in, step 2 for a new user: set the country"
      security:
        - publishableKey: []
      description: |
        For `fox_status=country_required`: creates the user with the
        chosen `country` and signs in, answering like
        `/v1/client/oauth/token`. The ticket works once, for 15 minutes.
        The country is checked before the ticket is used, so after
        `invalid_country` or `country_not_allowed` the user can pick
        another country with the same ticket. If a user with the same
        email signed up in the meantime, the Google account is linked to
        that user instead. Records `user.created` and `user.signed_in`
        with `method: google`. Counts toward the limit of 20 code checks
        per minute per IP address.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/OAuthCompleteInput" }
      responses:
        "200":
          description: Signed in, or `mfa_required`
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SignInResult" }
        "400":
          description: "`invalid_code` (the ticket is wrong, used or expired; start again) or `invalid_country`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403":
          description: "`account_locked`: the user this Google account belongs to is not active."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "422": { $ref: "#/components/responses/CountryNotAllowed" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /v1/client/sign_in/mfa:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    post:
      tags: [End-user API (SDK)]
      summary: "Second sign-in step: complete the TOTP or recovery-code challenge"
      security: []
      description: |
        Completes an `mfa_required` challenge from sign-up, sign-in, the
        email code, Google sign-in or a password reset. `mfa_token` expires
        after 5 minutes or 5 wrong codes (`401 invalid_mfa_token`); a wrong
        code under that is `400 invalid_mfa_code`.

        Unlike the other sign-in steps, this one does **not**
        check `X-Fox-Publishable-Key` (or any other credential) — the
        possession of a valid, unexpired `mfa_token` is what authorizes
        the call. Documented as implemented; flagged separately as worth
        a second look.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/MfaVerifyInput" }
      responses:
        "200":
          description: Signed in
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Session" }
        "400":
          description: "`invalid_mfa_code`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "401":
          description: "`invalid_mfa_token`: the challenge expired, was already used, or had too many wrong codes. Sign in again."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /v1/client/password_reset:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    post:
      tags: [End-user API (SDK)]
      summary: "Password reset, step 1: email a code"
      security:
        - publishableKey: []
      description: Always answers `202 code_sent`, whether or not the account exists or is active.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/EmailInput" }
      responses:
        "202":
          description: code_sent
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Accepted" }
              example: { status: code_sent }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /v1/client/password_reset/confirm:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    post:
      tags: [End-user API (SDK)]
      summary: "Password reset, step 2: set the new password and sign in"
      security:
        - publishableKey: []
      description: Ends every other session (sign-out everywhere) before signing in on this one.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/PasswordResetConfirmInput" }
      responses:
        "200":
          description: Signed in, or `mfa_required`
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SignInResult" }
        "400":
          description: "`invalid_code` or `weak_password`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /v1/client/token:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    post:
      tags: [End-user API (SDK)]
      summary: Refresh the session
      security:
        - publishableKey: []
      description: |
        Single-use, rotating refresh token. Presenting a refresh token
        that was already used revokes the whole session immediately
        (both holders lose it — one of them is an attacker). Rate-limited
        to 600 refreshes/minute per IP (shared NATs refresh a lot).
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/RefreshTokenInput" }
      responses:
        "200":
          description: A new token pair
          content:
            application/json:
              schema: { $ref: "#/components/schemas/TokenPair" }
        "401":
          description: "`invalid_refresh_token`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /v1/client/sign_out:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    post:
      tags: [End-user API (SDK)]
      summary: Sign out
      security:
        - publishableKey: []
      description: Revokes the session behind `refresh_token`. Always `204`, even if the token is already invalid.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/RefreshTokenInput" }
      responses:
        "204": { description: Signed out }
        "401": { $ref: "#/components/responses/Unauthorized" }

  /v1/client/mfa/totp/setup:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    post:
      tags: [End-user API (SDK)]
      summary: Start TOTP setup
      description: Not active until `/mfa/totp/enable`. Calling it again replaces the pending secret.
      security:
        - endUserToken: []
      responses:
        "200":
          description: Secret and otpauth URL to show as a QR code
          content:
            application/json:
              schema: { $ref: "#/components/schemas/TotpSetup" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "409":
          description: "`mfa_already_enabled`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /v1/client/mfa/totp/enable:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    post:
      tags: [End-user API (SDK)]
      summary: Enable TOTP
      description: Turns TOTP on after the first correct code and returns 10 one-time recovery codes, shown only here.
      security:
        - endUserToken: []
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/TotpCodeInput" }
      responses:
        "200":
          description: Recovery codes
          content:
            application/json:
              schema: { $ref: "#/components/schemas/TotpEnabled" }
        "400":
          description: "`invalid_mfa_code`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "409":
          description: "`mfa_already_enabled`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /v1/client/mfa/totp/disable:
    servers:
      - url: https://eu.auth.foxlogin.app
      - url: https://tr.auth.foxlogin.app
    post:
      tags: [End-user API (SDK)]
      summary: Disable TOTP
      description: Needs a current TOTP code or a recovery code. Removes all recovery codes too.
      security:
        - endUserToken: []
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/TotpCodeInput" }
      responses:
        "204": { description: Disabled }
        "400":
          description: "`invalid_mfa_code`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "401": { $ref: "#/components/responses/Unauthorized" }

components:
  securitySchemes:
    secretKey:
      type: http
      scheme: bearer
      description: |
        Application secret key, `sk_live_eu_…` or `sk_live_tr_…`, for your
        server. It works for one application. Every application gets one
        `admin` key when it is created (`secret_key` in the
        `POST /applications` response); create more with
        `POST /applications/{app_id}/secret_keys`. The key's role sets its
        scopes:

        | Role | Label | Scopes |
        | --- | --- | --- |
        | `admin` | Full access | applications:read, applications:write, users:read, users:write, events:read |
        | `editor` | Read and write users | applications:read, users:read, users:write, events:read |
        | `viewer` | Read only | applications:read, users:read, events:read |

        Any other application answers `404 not_found`, and
        `GET /applications` lists only the key's own application.
        `POST /applications` and the `/api_keys` endpoints answer
        `403 secret_key_not_allowed`. An unknown or revoked key answers
        `401 invalid_api_key`.
    tenantKey:
      type: http
      scheme: bearer
      description: |
        Organization API key, `fk_live_…`. It works for every application of
        the organization and can create applications. Its scopes are chosen
        when it is created with `POST /api_keys`. By default a key has
        `applications:read`, `applications:write`, `users:read`,
        `users:write` and `events:read`. `keys:write` (create and revoke
        keys) is added only when it is asked for, by a dashboard owner or
        admin or by a key that has `keys:write` itself. No key can give
        another key a scope it lacks.
    dashboardSession:
      type: http
      scheme: bearer
      description: |
        A dashboard person's own Fox Login session token (not a tenant API
        key). `GET /me` and `POST /me/tenants` accept this alone; every
        other endpoint that accepts it also needs `X-Fox-Tenant`, and the
        scopes follow the member's role in that tenant (see the Dashboard
        tag description).
    publishableKey:
      type: apiKey
      in: header
      name: X-Fox-Publishable-Key
      description: |
        An application's publishable key (safe to ship in client code),
        sent by the Fox Login SDKs on every End-user API call. Looked up
        per request; an unknown key is `401 invalid_publishable_key`.
    endUserToken:
      type: http
      scheme: bearer
      description: |
        The end user's own `access_token` from sign-in (not a
        publishable key). 10-minute lifetime; a session that was signed
        out, or whose password was reset, is rejected even if `exp`
        has not passed. The TOTP setup/enable/disable endpoints take
        only this — the application is read from the token itself, so
        they do **not** also require `X-Fox-Publishable-Key`.

  responses:
    BadRequest:
      description: Invalid request
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    Unauthorized:
      description: "Missing or invalid key or token. The Management API answers `missing_api_key` (no Bearer token) or `invalid_api_key` (unknown or revoked secret key or organization API key)."
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    NotFound:
      description: Not found
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    Forbidden:
      description: "`missing_scope` (the role or scopes of the key, or the dashboard role, lack the scope), `secret_key_not_allowed` (a secret key called an endpoint for the whole organization) or `not_a_member` (X-Fox-Tenant names a tenant the caller does not belong to)."
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
          examples:
            missing_scope:
              value:
                error: { code: missing_scope, message: "This key or role lacks the users:write scope.", region: null, retryable: false, details: {} }
            secret_key_not_allowed:
              value:
                error: { code: secret_key_not_allowed, message: "Secret keys work only inside their own application. Use an organization API key.", region: null, retryable: false, details: {} }
    RateLimited:
      description: "`rate_limited`. Retry after `Retry-After` seconds."
      headers:
        Retry-After:
          description: Seconds to wait before retrying
          schema: { type: integer, example: 60 }
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
          example:
            error: { code: rate_limited, message: Too many attempts. Wait a minute and try again., region: null, retryable: true, details: {} }
    CountryNotAllowed:
      description: |
        `country_not_allowed`: the application only accepts users from the
        countries listed in `country_restriction.countries`.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
          example:
            error:
              code: country_not_allowed
              message: This application only accepts users from TR.
              region: TR
              retryable: false
              details: { country: DE, country_region: EU, application_region: TR }
    RegionUnavailable:
      description: "`region_unavailable`: the user's region cannot answer right now. Retry after `Retry-After` seconds."
      headers:
        Retry-After:
          description: Seconds to wait before retrying
          schema: { type: integer, example: 30 }
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
          example:
            error:
              code: region_unavailable
              message: The TR region is not available right now.
              region: TR
              retryable: true
              details: {}

  parameters:
    AppId:
      name: app_id
      in: path
      required: true
      schema: { type: string, example: app_seller }
    UserId:
      name: user_id
      in: path
      required: true
      schema: { type: string, example: usr_tr_8f2c91a7 }
    Fields:
      name: fields
      in: query
      description: "Comma list. Default: id,email,name,region,labels,status"
      schema: { type: string, example: "email,labels" }
    TenantHeader:
      name: X-Fox-Tenant
      in: header
      description: Required when authenticating with a dashboard session token instead of a tenant API key.
      schema: { type: string, example: ten_8f2c91a7 }

  schemas:
    Region:
      type: string
      enum: [EU, TR]
      description: More regions will be added; clients must accept unknown values.
    RegionsUnavailable:
      type: array
      description: Regions that did not answer. Their results are missing.
      items: { $ref: "#/components/schemas/Region" }
      example: []
    Partial:
      type: boolean
      description: "`true` when one or more regions did not answer and the results are incomplete."
      default: false
    Error:
      type: object
      required: [error]
      properties:
        error:
          type: object
          required: [code, message, retryable]
          properties:
            code: { type: string, example: region_unavailable, description: "Stable machine code, e.g. email_exists, country_not_allowed, user_moved, method_not_available, region_unavailable" }
            message: { type: string, description: "Plain English, for developers" }
            region: { oneOf: [{ $ref: "#/components/schemas/Region" }, { type: "null" }], description: "Region that produced the error, if any" }
            retryable: { type: boolean }
            details: { type: object, additionalProperties: true }
    SignInMethod:
      type: string
      enum: [password, magic_link, email_code, phone_code, passkey, google, apple, microsoft, github]
      description: |
        Part of the planned `sign_in_methods` setting. Methods not yet
        available would return `422 method_not_available`. Available today:
        password, email_code and google (turned on or off with
        `providers.google.enabled`), plus TOTP 2FA.
    Sector:
      type: string
      enum: [ecommerce, saas, education, health, finance, fintech, payments, insurance, government, telecom, crypto, gaming, media, other]
      description: |
        finance, fintech, payments, insurance, health, government, telecom and
        crypto show a warning and a contact address in the dashboard. Banks,
        payment institutions and e-money institutions are excluded by the
        Terms.
    NewDeviceSignIn:
      type: object
      description: "When a user signs in from a device not seen before: send a notification email; optionally require an email code. Off by default."
      properties:
        enabled: { type: boolean, default: false }
        require_email_code: { type: boolean, default: false }
    ApplicationCreateInput:
      type: object
      description: The body `POST /applications` actually accepts.
      required: [name, region]
      properties:
        name: { type: string, minLength: 1, maxLength: 100 }
        region:
          $ref: "#/components/schemas/Region"
          description: All end users of this application are stored in this region, whatever country they choose (single-region applications). Cannot be changed after creation; `PATCH` answers `422 region_immutable`.
        sector: { $ref: "#/components/schemas/Sector" }
        user_countries:
          type: array
          description: Informational only today; does not affect sign-up. ISO 3166-1 alpha-2.
          items: { type: string, pattern: "^[A-Z]{2}$" }
          example: [TR]
          default: []
        country_restriction:
          type: object
          description: |
            Default `all`: users from every country can sign up and are stored
            in the application's region. Accepting users from countries with
            their own data-location rules (for example Russia or China) is the
            tenant's responsibility under the DPA. `only_listed`: only the
            listed countries can sign up; others get `422 country_not_allowed`.
          properties:
            mode: { type: string, enum: [all, only_listed], default: all }
            countries:
              type: array
              items: { type: string, pattern: "^[A-Z]{2}$" }
              example: [TR]
    ApplicationUpdateInput:
      type: object
      description: The body `PATCH /applications/{app_id}` accepts. Every field is optional; send only the fields you change.
      properties:
        name: { type: string, minLength: 1, maxLength: 100 }
        region:
          $ref: "#/components/schemas/Region"
          description: Optional. Must equal the application's region; any other value is `422 region_immutable`.
        redirect_urls:
          type: array
          maxItems: 20
          description: |
            Replaces the whole list. The exact URLs Google sign-in may send
            users back to. `https`, or `http` for `localhost`, `127.0.0.1`
            and `[::1]`; a host, no user name or password, no `#`, `*` or
            spaces, at most 500 characters each. Duplicates are dropped.
            With an empty list, Google sign-in cannot start.
          items: { type: string, format: uri, maxLength: 500 }
          example: ["https://anka.io/auth/callback", "http://localhost:3000/auth/callback"]
        country_restriction:
          type: object
          description: Replaces the stored restriction. A missing `mode` means `all`, missing `countries` means `[]`.
          properties:
            mode: { type: string, enum: [all, only_listed], default: all }
            countries:
              type: array
              items: { type: string, pattern: "^[A-Z]{2}$" }
              example: [TR]
        providers:
          type: object
          properties:
            google:
              type: object
              required: [enabled]
              properties:
                enabled: { type: boolean, description: "Turns Google sign-in on or off for this application. On by default." }
    ApplicationInput:
      description: |
        Settings planned for `PATCH /applications/{app_id}` beyond
        `ApplicationUpdateInput`. Not accepted yet; `PATCH` ignores these
        fields today.
      allOf:
        - $ref: "#/components/schemas/ApplicationUpdateInput"
        - type: object
          properties:
            new_device_sign_in: { $ref: "#/components/schemas/NewDeviceSignIn" }
            sign_in_methods: { type: array, items: { $ref: "#/components/schemas/SignInMethod" } }
            mfa_policy: { type: string, enum: [off, optional, required], default: optional }
            email_verification:
              type: string
              enum: [fox_login, external, off]
              default: fox_login
              description: "fox_login = we send from no-reply@foxlogin.app in the user's language. external and off are not implemented; Fox Login always sends its own verification/code emails today."
            emails_enabled:
              type: object
              description: "Turn single Fox Login emails on/off, e.g. { welcome: false }"
              additionalProperties: { type: boolean }
            mfa_factors: { type: array, items: { type: string, enum: [totp, passkey, sms, backup_codes] }, description: "Only `totp` is implemented." }
            sms:
              type: object
              properties:
                sender_name: { type: string, example: ANKA }
                template: { type: string, example: "{code} is your Anka code." }
                allowed_countries: { type: array, items: { type: string } }
            environments:
              type: array
              items: { type: string, enum: [development, production] }
              default: [development, production]
    Application:
      type: object
      description: The application as `GET`, `POST` and `PATCH /applications` return it.
      properties:
        id: { type: string, example: app_seller }
        name: { type: string }
        region: { $ref: "#/components/schemas/Region", readOnly: true }
        multi_region: { type: boolean, readOnly: true, default: false, description: Not available yet; planned. }
        block:
          type: string
          enum: [west, east]
          readOnly: true
          default: west
          description: East block planned; operated by a separate company. Every application is `west` today.
        sector: { type: [string, "null"] }
        user_countries: { type: array, items: { type: string } }
        country_restriction:
          type: object
          properties:
            mode: { type: string, enum: [all, only_listed] }
            countries: { type: array, items: { type: string } }
        redirect_urls:
          type: array
          items: { type: string }
          description: The exact URLs Google sign-in may send users back to. Empty until you set them with `PATCH /applications/{app_id}`.
          example: ["https://anka.io/auth/callback"]
        providers:
          type: object
          description: Social sign-in providers. Google is the only one today.
          properties:
            google:
              type: object
              properties:
                enabled: { type: boolean, default: true, description: "On unless turned off with `PATCH /applications/{app_id}`." }
                mode: { type: string, enum: [platform], description: "`platform`: Fox Login's own Google app. Using your own Google app is planned." }
        publishable_key: { type: string, example: "pk_live_tr_8f2c91a7b3d04e5f" }
        created_at: { type: string, format: date-time }
    ApplicationWithKeys:
      description: |
        `Application` plus `secret_key`, the application's first secret key
        (name `Default`, role `admin`). The full `secret_key.key` appears
        only in this response. `publishable_key` is not secret and every
        later `GET` returns it again.
      allOf:
        - $ref: "#/components/schemas/Application"
        - type: object
          required: [secret_key]
          properties:
            secret_key: { $ref: "#/components/schemas/SecretKeyWithKey" }
    SecretKeyRole:
      type: string
      enum: [admin, editor, viewer]
      description: "`admin` (Full access), `editor` (Read and write users) or `viewer` (Read only). The `secretKey` security scheme lists the scopes of each role."
    SecretKeyInput:
      type: object
      properties:
        name: { type: string, maxLength: 60, default: Secret key, description: "Shown in the dashboard. Missing or empty means `Secret key`.", example: Billing worker }
        role: { $ref: "#/components/schemas/SecretKeyRole", default: admin }
    SecretKey:
      type: object
      properties:
        id: { type: string, example: key_3b7e10c2 }
        name: { type: string, example: Billing worker }
        role: { $ref: "#/components/schemas/SecretKeyRole" }
        prefix: { type: string, description: "First 15 characters, to tell keys apart. Show it as `sk_live_eu_Q9xT…`.", example: sk_live_eu_Q9xT }
        created_at: { type: string, format: date-time }
        created_by: { type: [string, "null"], description: "User ID of the dashboard person who created the key; `null` when an organization API key created it.", example: usr_eu_8f2c91a7 }
        last_used_at: { type: [string, "null"], format: date-time, description: Updated at most once a minute. }
        revoked_at: { type: [string, "null"], format: date-time }
    SecretKeyWithKey:
      type: object
      description: A new secret key. The full `key` appears only in this response; only its hash is stored.
      properties:
        id: { type: string, example: key_3b7e10c2 }
        name: { type: string, example: Billing worker }
        role: { $ref: "#/components/schemas/SecretKeyRole" }
        prefix: { type: string, example: sk_live_eu_Q9xT }
        key: { type: string, description: "The full key. Send it as `Authorization: Bearer <key>`.", example: sk_live_eu_Q9xTa7Lm2Nb4Vc6Xz8Sd1Fg3Hj5Kl7Pq9Wr2Ey4Tu6I }
        created_at: { type: string, format: date-time }
        created_by: { type: [string, "null"], example: usr_eu_8f2c91a7 }
        last_used_at: { type: "null" }
    ProviderInput:
      type: object
      properties:
        enabled: { type: boolean }
        mode: { type: string, enum: [platform, custom], default: platform }
        credentials:
          type: object
          description: "Only for mode=custom. Google: client_id, client_secret. Apple: team_id, services_id, key_id, private_key. GitHub/Microsoft: client_id, client_secret."
          additionalProperties: true
        notify_affected_users: { type: boolean, default: true, description: "Apple mode switch only" }
    Provider:
      type: object
      properties:
        provider: { type: string }
        enabled: { type: boolean }
        mode: { type: string, enum: [platform, custom] }
        status: { type: string, enum: [ready, connected, not_configured, error] }
        redirect_url: { type: string, example: "https://auth.seller.anka.io/v1/oauth/apple/callback" }
        shown_name: { type: string, description: "Name users see on the provider screen", example: Fox Login }
        apple_relink:
          type: object
          properties:
            affected: { type: integer, example: 128 }
            relinked: { type: integer, example: 87 }
            waiting: { type: integer, example: 41 }
    Labels:
      type: object
      additionalProperties:
        oneOf:
          - type: string
          - type: array
            items: { type: string }
      example: { store: mavi-ev-tekstil, store_role: [owner], plan: growth }
    LabelGroup:
      type: object
      properties:
        key: { type: string, example: store }
        name: { type: string, example: Store }
        selection: { type: string, enum: [single, multiple] }
        in_session_token: { type: boolean, default: true }
        at_sign_up:
          type: string
          enum: [hidden, user_picks, automatic]
          description: "user_picks = shown on the sign-up page (allowed labels only). automatic = from invite link, email domain rule or API."
        user_pickable_labels: { type: array, items: { type: string }, example: [manager, staff, cashier] }
        domain_rules:
          type: array
          items:
            type: object
            properties:
              email_domain: { type: string, example: maviev.com.tr }
              label: { type: string, example: mavi-ev-tekstil }
        required_at_sign_up: { type: boolean, default: false }
        api_only: { type: boolean, default: false }
        labels:
          type: array
          items:
            type: object
            properties:
              key: { type: string }
              name: { type: string }
              color: { type: string }
    TextMatch:
      type: object
      description: Exactly one operator. Case and accents are ignored.
      minProperties: 1
      maxProperties: 1
      properties:
        equals: { type: string }
        contains: { type: string }
        starts_with: { type: string }
        ends_with: { type: string }
      example: { contains: "kaya" }
    DateRange:
      type: object
      properties:
        gte: { type: string, format: date-time }
        lt: { type: string, format: date-time }
    UserFilter:
      type: object
      description: All given conditions must match (AND). Use `any` for OR.
      properties:
        ids: { type: array, maxItems: 100, items: { type: string }, description: "User IDs you already store" }
        name: { $ref: "#/components/schemas/TextMatch" }
        email: { $ref: "#/components/schemas/TextMatch" }
        phone: { $ref: "#/components/schemas/TextMatch" }
        labels: { $ref: "#/components/schemas/Labels" }
        region: { type: array, items: { $ref: "#/components/schemas/Region" } }
        country: { type: array, items: { type: string }, description: "ISO 3166-1 alpha-2" }
        status: { type: array, items: { type: string, enum: [active, locked, banned, invited] } }
        email_verified: { type: boolean }
        created_at: { $ref: "#/components/schemas/DateRange" }
        last_sign_in_at: { $ref: "#/components/schemas/DateRange" }
        any:
          type: array
          description: At least one of these filters must match (OR)
          items: { $ref: "#/components/schemas/UserFilter" }
    UserSearchRequest:
      type: object
      required: [filter]
      properties:
        filter: { $ref: "#/components/schemas/UserFilter" }
        fields:
          type: array
          items: { type: string, enum: [id, region, email, phone, name, country, labels, status, created_at, last_sign_in_at] }
          default: [id, region]
        sort:
          type: string
          enum: [created_at, -created_at, last_sign_in_at, -last_sign_in_at, name, -name]
          default: -created_at
        limit: { type: integer, default: 20, maximum: 100 }
        cursor: { type: string }
    User:
      type: object
      description: |
        `id`, `region`, `email`, `email_verified`, `name`, `country`,
        `status`, `labels`, `created_at` and `last_sign_in_at` are
        returned today. `phone`, `sessions`, `mfa_factors`,
        `sign_in_history`, `metadata` and `consents` are not implemented
        (no `phone` sign-in, no `fields`/`expand` selection yet) and are
        never present on a live response.
      properties:
        id: { type: string }
        region: { $ref: "#/components/schemas/Region" }
        email: { type: string }
        email_verified: { type: boolean }
        phone: { type: string, description: Not available yet. }
        name: { type: string }
        country: { type: string }
        labels: { $ref: "#/components/schemas/Labels" }
        status: { type: string, enum: [active, locked, banned, invited] }
        created_at: { type: string, format: date-time }
        last_sign_in_at: { type: string, format: date-time }
        sessions: { type: array, items: { type: object }, description: "Not available yet (planned expand=sessions)." }
        mfa_factors: { type: array, items: { type: string }, description: "Not available yet (planned expand=mfa_factors)." }
        sign_in_history: { type: array, items: { type: object }, description: "Not available yet (planned expand=sign_in_history)." }
        metadata: { type: object, description: "Not available yet (planned expand=metadata)." }
        consents: { type: array, items: { type: object }, description: "Not available yet (planned expand=consents)." }
    UserExport:
      allOf:
        - $ref: "#/components/schemas/User"
        - type: object
          properties:
            events: { type: array, items: { $ref: "#/components/schemas/Event" } }
            devices: { type: array, items: { type: object } }
            exported_at: { type: string, format: date-time }
    Event:
      type: object
      description: |
        No `region` or `location` field: events are returned from the
        application's single region, which you already know (see
        `Application.region`); there is no cross-region merge.
      properties:
        id: { type: string, example: evt_8f2c91a7 }
        type:
          type: string
          example: sign_in.failed
          description: >
            user.created, user.signed_in, sign_in.failed, password.reset,
            mfa.enrolled, mfa.removed, sign_in.mfa_required,
            sign_up.existing_email and identity.linked (a Google account
            was linked to an existing user with the same email;
            `data.provider` is `google`). The last two are not in
            `WebhookEventType`. Google sign-ins record `user.created` and
            `user.signed_in` with `data.method` `google`.
        user_id: { type: [string, "null"] }
        ip: { type: [string, "null"] }
        user_agent: { type: [string, "null"] }
        created_at: { type: string, format: date-time }
        data: { type: object }
    Job:
      type: object
      properties:
        job_id: { type: string, example: job_9x2k }
        type: { type: string, enum: [user_erasure, user_export, user_move, application_deletion] }
        status: { type: string, enum: [queued, running, completed, failed] }
        region: { $ref: "#/components/schemas/Region" }
        backups_purged_by: { type: string, format: date }
    Jwks:
      type: object
      properties:
        keys:
          type: array
          items:
            type: object
            required: [kty, crv, x, kid, use, alg]
            properties:
              kty: { type: string, const: OKP }
              crv: { type: string, const: Ed25519 }
              x: { type: string, description: "Public key, base64url" }
              kid: { type: string, example: tr-v1, description: "<region>-v<N>" }
              use: { type: string, const: sig }
              alg: { type: string, const: EdDSA }
    SessionTokenClaims:
      type: object
      description: |
        Claims in an end-user or dashboard access token (JWT, EdDSA).
        Signed by the token's region with the key named in the header
        `kid`. Lifetime is 600 seconds (10 minutes).
      properties:
        sub: { type: string, description: User ID, example: usr_tr_8f2c91a7 }
        rgn: { $ref: "#/components/schemas/Region" }
        app: { type: string, description: Application ID, example: app_seller }
        sid: { type: string, description: "Session ID. Revoking the session (sign-out, password reset, refresh-token reuse) invalidates tokens with this sid immediately, even before exp.", example: ses_8f2c91a7 }
        labels: { $ref: "#/components/schemas/Labels" }
        iat: { type: integer, description: Issued at (Unix seconds) }
        exp: { type: integer, description: "Expires at (Unix seconds). 600 seconds after iat." }
        iss: { type: string, const: "https://api.foxlogin.app", description: "Fixed issuer for every region; it is not the region host." }

    EndUserProfile:
      type: object
      description: The end-user object returned by the End-user API (SDK). Has no `phone` field; phone sign-in is not implemented.
      properties:
        id: { type: string, example: usr_tr_8f2c91a7 }
        region: { $ref: "#/components/schemas/Region" }
        email: { type: string }
        email_verified: { type: boolean }
        name: { type: [string, "null"] }
        country: { type: string, description: ISO 3166-1 alpha-2 }
        status: { type: string, example: active, description: "Only `active` is reachable through the SDK; other statuses cannot sign in." }
        labels: { $ref: "#/components/schemas/Labels" }
        created_at: { type: string, format: date-time }
        last_sign_in_at: { type: [string, "null"], format: date-time }
    TokenPair:
      type: object
      description: Issued by sign-up, sign-in, the MFA step and `/token`.
      properties:
        session_id: { type: string, example: ses_8f2c91a7 }
        access_token: { type: string, description: "JWT, 10-minute lifetime. Verify with GET /.well-known/jwks.json." }
        refresh_token: { type: string, description: Opaque. Single-use; rotates on every `/token` call. Presenting an already-used one revokes the whole session. }
        token_type: { type: string, const: Bearer }
        expires_in: { type: integer, const: 600, description: Seconds until `access_token` expires. }
    Session:
      type: object
      description: A completed sign-in.
      properties:
        user: { $ref: "#/components/schemas/EndUserProfile" }
        session_id: { type: string }
        access_token: { type: string }
        refresh_token: { type: string }
        token_type: { type: string, const: Bearer }
        expires_in: { type: integer, const: 600 }
    MfaRequired:
      type: object
      description: The first step (password, code or Google) was right, but the account has TOTP on; complete `POST /v1/client/sign_in/mfa` with this token.
      required: [status, mfa_token]
      properties:
        status: { type: string, const: mfa_required }
        mfa_token: { type: string, description: "Opaque, 5-minute lifetime, 5 wrong codes invalidate it (`invalid_mfa_token`)." }
    SignInResult:
      description: A session, or `mfa_required` when the account has two-factor authentication on.
      oneOf:
        - $ref: "#/components/schemas/Session"
        - $ref: "#/components/schemas/MfaRequired"
    Accepted:
      type: object
      description: Always returned, whether or not the email has an account, so the response cannot be used to probe for registered addresses.
      required: [status]
      properties:
        status: { type: string }
    Me:
      type: object
      properties:
        user_id: { type: string, description: ID in the dashboard's own Fox Login application (EU region)., example: usr_eu_8f2c91a7 }
        region: { type: string, description: "Region claim from the session token (`rgn`); always EU for the dashboard app.", example: EU }
        tenants:
          type: array
          items:
            type: object
            properties:
              id: { type: string, example: ten_8f2c91a7 }
              name: { type: string }
              role: { type: string, enum: [owner, admin, developer, viewer] }
              created_at: { type: string, format: date-time }
    TenantApiKey:
      type: object
      properties:
        id: { type: string, example: key_8f2c91a7 }
        name: { type: string }
        prefix: { type: string, description: "First 12 characters, to tell keys apart in the dashboard.", example: fk_live_8f2c }
        scopes: { type: array, items: { $ref: "#/components/schemas/OrganizationScope" } }
        created_at: { type: string, format: date-time }
        last_used_at: { type: [string, "null"], format: date-time, description: Updated at most once a minute. }
        revoked_at: { type: [string, "null"], format: date-time }
    OrganizationScope:
      type: string
      enum: [applications:read, applications:write, users:read, users:write, events:read, keys:write]
      description: "A scope of an organization API key. `keys:write` is never given by default."
    TenantApiKeyWithSecret:
      allOf:
        - $ref: "#/components/schemas/TenantApiKey"
        - type: object
          properties:
            key: { type: string, description: The full key. Shown only in this response; only its hash is stored., example: "fk_live_8f2c91a7b3d04e5f" }
    WebhookEventType:
      type: string
      enum: [user.created, user.signed_in, sign_in.failed, password.reset, mfa.enrolled, mfa.removed, sign_in.mfa_required]
      description: "Event types a webhook endpoint can subscribe to by name, or `*` for all. The event log also contains `sign_up.existing_email` and `identity.linked`, which cannot be subscribed to by name; an endpoint subscribed to `*` receives them too."
    WebhookEndpointInput:
      type: object
      required: [url, events]
      properties:
        url: { type: string, format: uri, description: "Must be https, a public hostname (no IP literal, port, credentials, localhost or .internal/.local suffix), at most 500 characters.", example: "https://hooks.anka.com.tr/fox" }
        events:
          type: array
          minItems: 1
          items: { oneOf: [{ $ref: "#/components/schemas/WebhookEventType" }, { type: string, const: "*" }] }
          example: [user.created, user.signed_in]
    WebhookEndpoint:
      type: object
      properties:
        id: { type: string, example: whe_8f2c91a7 }
        url: { type: string }
        events: { type: array, items: { type: string } }
    WebhookEndpointWithSecret:
      allOf:
        - $ref: "#/components/schemas/WebhookEndpoint"
        - type: object
          properties:
            secret: { type: string, description: "Signs deliveries (Standard Webhooks). Shown only in this response.", example: "whsec_8f2c91a7b3d04e5f..." }
    WebhookDelivery:
      type: object
      description: |
        A delivery is a `POST` to the endpoint URL with headers
        `webhook-id`, `webhook-timestamp` and `webhook-signature`
        (Standard Webhooks: https://www.standardwebhooks.com), signed with
        the endpoint's secret. The body carries ids only, not personal
        data: `{id, type, created_at, data: {app_id, user_id, ...}}`.
        Failed deliveries retry with backoff, up to 8 attempts.
      properties:
        id: { type: string, example: whd_evt123_whe456 }
        type: { $ref: "#/components/schemas/WebhookEventType" }
        created_at: { type: string, format: date-time }
        data:
          type: object
          required: [app_id, user_id]
          properties:
            app_id: { type: string }
            user_id: { type: [string, "null"] }

    SignUpInput:
      type: object
      required: [email, password, country]
      properties:
        email: { type: string, format: email }
        password: { type: string, minLength: 8, maxLength: 256 }
        country: { type: string, description: ISO 3166-1 alpha-2, example: TR }
        name: { type: string }
    VerifyCodeInput:
      type: object
      required: [email, code]
      properties:
        email: { type: string, format: email }
        code: { type: string, description: "Six-digit code, valid 15 minutes.", example: "482913" }
    SignInInput:
      type: object
      required: [email, password]
      properties:
        email: { type: string, format: email }
        password: { type: string }
    EmailInput:
      type: object
      required: [email]
      properties:
        email: { type: string, format: email }
    PasswordResetConfirmInput:
      type: object
      required: [email, code, password]
      properties:
        email: { type: string, format: email }
        code: { type: string }
        password: { type: string, minLength: 8, maxLength: 256 }
    RefreshTokenInput:
      type: object
      required: [refresh_token]
      properties:
        refresh_token: { type: string }
    OAuthCodeInput:
      type: object
      required: [code]
      properties:
        code: { type: string, description: "The `fox_code` query parameter from the redirect. Works once, for 2 minutes.", example: fxc_Q9xTa7Lm2Nb4Vc6Xz8Sd1Fg3Hj5Kl7Pq9Wr2Ey4Tu6I }
    OAuthCompleteInput:
      type: object
      required: [ticket, country]
      properties:
        ticket: { type: string, description: "The `fox_ticket` query parameter from the redirect. Works once, for 15 minutes.", example: fxc_Ab3dE5fG7hJ9kL1mN3pQ5rS7tU9vW1xY3zA5bC7dE9f }
        country: { type: string, description: "ISO 3166-1 alpha-2, in any case.", example: TR }
    MfaVerifyInput:
      type: object
      required: [mfa_token, code]
      properties:
        mfa_token: { type: string }
        code: { type: string, description: A current TOTP code or a recovery code. }
    TotpCodeInput:
      type: object
      required: [code]
      properties:
        code: { type: string, description: "For `disable`, a current TOTP code or a recovery code; for `enable`, a TOTP code only." }
    TotpSetup:
      type: object
      properties:
        secret: { type: string, description: "Base32 TOTP secret, to show as a manual-entry fallback." }
        otpauth_url: { type: string, description: "`otpauth://` URL to render as a QR code." }
    TotpEnabled:
      type: object
      properties:
        recovery_codes:
          type: array
          items: { type: string }
          description: 10 one-time codes. Shown only in this response; store them or ask the user to.
          example: ["a1b2c-3d4e5", "f6g7h-8i9j0"]
