Skip to content

Identity

Internals of the Identity domain. For the public API, see Identity API.

domain/identity in CoreAPI has two independent slices that share a folder, the same way the tenancy domain does (see Tenancy internals):

Slice Routes Token Router file
Native /api/v1/identity/* AuthAPI RS256 domain/identity/routes/routes.go
Ticketing /auth/*, /api/admin/:workspaceId/*, /api/customer/* HS256 (login, refresh, customers) and AuthAPI RS256 (admin and customer management) domain/identity/routes/routes_ticketing.go

For the login flow that produces the RS256 token, see Auth, identity and RBAC.

Native slice

GET /api/v1/identity/users/me (UserHandler.GetMe) reads the OrgClaim from the token and enriches it from CoreAPI's own database: the users row, platform_members, the organization name and default app, and the workspace list.

  • org is a single nullable object. One token holds one org.
  • If the caller's org role is ORG_OWNER or ORG_ADMIN, every workspace in the org is returned, each stamped WORKSPACE_ADMIN, whatever the real membership.
  • For everyone else the list is the UNION of workspace_members and team_workspace_roles (through team_members), deduplicated by workspace with the highest-ranked role winning (WORKSPACE_ADMIN > WORKSPACE_MEMBER > VIEWER).
  • The list is built by pkg/workspaces.ForUser, shared with the legacy flat-media fallback so both agree on workspaces[0]. It is sorted by workspace name, then ID (stable since 2026-10-01). See Playout workspace auth.
  • onboarded is true when the user has no users row, has no org, or has a non-null onboarding_completed_at. POST /identity/users/me/onboarding runs UPDATE users SET onboarding_completed_at = COALESCE(onboarding_completed_at, now()), so the first completion time is kept.
  • Errors from this slice are raw {"error": "..."} bodies. Success bodies are bare objects (identity and tenancy are the two platform-lane domains with no {success, data} envelope).

Ticketing slice

Manages authentication and user identity for the ticketing platform. It covers two account types, admins (staff with portal access) and customers (people who buy tickets). It issues HS256 JWTs and stores token pairs in a token table. Tokens are revoked on logout.

graph LR
    AdminFrontend["Admin portal"]
    CustomerApp["Customer app"]
    CoreAPI["CoreAPI (identity)"]
    DB["Ticketing DB\n(admin, customer, token)"]
    Email["Email service"]

    AdminFrontend -->|POST /auth/login userType=admin| CoreAPI
    CustomerApp -->|POST /auth/login userType=customer| CoreAPI
    CoreAPI --> DB
    CoreAPI -->|reset password email| Email

How login works

  • userType defaults to admin.
  • Admin login verifies the credentials through the sign-in service, then matches the returned identity-provider user ID to a local admin row (AdminRepository.FindByZitadelID). A missing row or a disabled admin returns invalid credentials / account is disabled.
  • Customer login checks a local bcrypt hash on the customer row.
  • The access and refresh tokens are HS256 JWTs. The userId claim is the admin ID (as a string) or the customer's custId. Role is the admin role or CUSTOMER.
  • SaveToken failures are logged and ignored, so a login can succeed without a stored token row.
  • The password reset endpoints generate a random 12-character password, store its bcrypt hash and email the new password. They always return success so the response does not reveal whether an email exists.

Authorization on the management routes

Step 6 of the ticketing multi-tenancy work swapped the flat role checks for per-request workspace permissions. The swap is deliberately partial:

  • GET/PUT /api/admin/:workspaceId/profile and PUT .../password act only on the caller's own admin row, resolved from the caller's identity-provider ID by resolveLegacyAdminID (it sets the userId local to the legacy admin.AdminId). No admin ID comes from the request, so there is no cross-tenant risk, and the permission check is the whole fix.
  • GET/POST/PUT/DELETE /api/admin/:workspaceId/management and GET /api/customer/:workspaceId/management are true multi-record management routes. The admin and customer tables have no organization_id or workspace_id column, so these five routes check a permission but return every admin or customer in the database. Partitioning them needs a column on admin and customer, which is blocked on two open product questions: whether admin (already recommended for retirement, no foreign keys, its role column unused for real authorization) should be extended or replaced by public.users, and whether customer should be per-organization at all.
  • GET /api/customer/profile is public and keyed by the custId query parameter. Anyone who knows an ID can read that customer's profile.

Notification side effects

Several handlers write a notification row for the ticketing admin feed (customer registration, profile or password changes, password resets). Customer-side notifications use the single pinned workspace from the SPATIO_TICKETING_WORKSPACE_ID environment variable, because the customer app has no per-request workspace. Admin-side notifications use the :workspaceId of the request. A notification failure on registration or customer update returns an error to the caller after the change is saved.

Data model

erDiagram
    Admin {
        uint adminId
        string username
        string fullName
        string role
        string email
        string contactNo
        bool isDisabled
    }

    Customer {
        string custId
        string email
        string identificationNo
        string fullName
        string contactNo
        bool isDisabled
    }

    Token {
        uint tokenId
        string userId
        string userType
        string accessToken
        string refreshToken
        string ipAddress
        string userAgent
    }

    CustomerLog {
        uint custLogId
        string custId
        string type
        string title
        string message
        string date
    }

    AuditLog {
        uint auditLogId
        string userId
        string authorityLevel
        string logType
        string logAction
    }

    Admin ||--o{ Token : "has tokens"
    Customer ||--o{ Token : "has tokens"
    Customer ||--o{ CustomerLog : "has logs"

Roles

Role Scope Capabilities
SYSADMIN Platform Full access including admin management
ADMIN Platform Manage tickets, orders, customers
MEMBER Platform Read-only admin access
CUSTOMER End user Manage own profile and orders

These roles are stored on the admin row. Authorization on the RS256 routes no longer reads them (see above). Only HasCustomerRole still gates on a role directly, for the customer self-service routes.

Caching

GET /api/customer/:workspaceId/management results are cached in Redis for 30 seconds, keyed by page, limit and query. Customer writes delete the customers:management:* keys.

Known gaps and code notes

  • The five management routes are not partitioned by organization (see above).
  • DELETE /api/admin/:workspaceId/management takes the admin ID in the request body.
  • PUT /api/admin/:workspaceId/management with isDisabled does not revoke the admin's existing tokens (the token removal helper is a placeholder).
  • Unlike the other customer routes, PUT /api/customer/profile requires email and identificationNo in the body even though the profile edit form changes only the name and phone number.
  • CustomerHandler.ListCustomers exists but is not routed.

Change history

Date Change
2026-06-23 Initial identity domain documentation.
2026-09-20 Native slice (/api/v1/identity/users/me) documented.
2026-10-01 GET /identity/users/me workspace list sorted by name then ID (shared pkg/workspaces.ForUser), so workspaces[0] is stable.
2026-11-16 Admin and customer management routes moved under /api/admin/{workspaceId} and /api/customer/{workspaceId}/management with RS256 and workspace permissions (documented from code). POST /identity/users/me/onboarding and the onboarded and default_app fields added to the docs.