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.
orgis a single nullable object. One token holds one org.- If the caller's org role is
ORG_OWNERorORG_ADMIN, every workspace in the org is returned, each stampedWORKSPACE_ADMIN, whatever the real membership. - For everyone else the list is the
UNIONofworkspace_membersandteam_workspace_roles(throughteam_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 onworkspaces[0]. It is sorted by workspace name, then ID (stable since 2026-10-01). See Playout workspace auth. onboardedistruewhen the user has nousersrow, has no org, or has a non-nullonboarding_completed_at.POST /identity/users/me/onboardingrunsUPDATE 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¶
userTypedefaults toadmin.- Admin login verifies the credentials through the sign-in service, then matches the returned identity-provider user ID to a local
adminrow (AdminRepository.FindByZitadelID). A missing row or a disabled admin returnsinvalid credentials/account is disabled. - Customer login checks a local bcrypt hash on the
customerrow. - The access and refresh tokens are HS256 JWTs. The
userIdclaim is the admin ID (as a string) or the customer'scustId.Roleis the admin role orCUSTOMER. SaveTokenfailures 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/profileandPUT .../passwordact only on the caller's own admin row, resolved from the caller's identity-provider ID byresolveLegacyAdminID(it sets theuserIdlocal to the legacyadmin.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/managementandGET /api/customer/:workspaceId/managementare true multi-record management routes. Theadminandcustomertables have noorganization_idorworkspace_idcolumn, so these five routes check a permission but return every admin or customer in the database. Partitioning them needs a column onadminandcustomer, which is blocked on two open product questions: whetheradmin(already recommended for retirement, no foreign keys, itsrolecolumn unused for real authorization) should be extended or replaced bypublic.users, and whethercustomershould be per-organization at all.GET /api/customer/profileis public and keyed by thecustIdquery 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/managementtakes the admin ID in the request body.PUT /api/admin/:workspaceId/managementwithisDisableddoes not revoke the admin's existing tokens (the token removal helper is a placeholder).- Unlike the other customer routes,
PUT /api/customer/profilerequiresemailandidentificationNoin the body even though the profile edit form changes only the name and phone number. CustomerHandler.ListCustomersexists 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. |