SystemsAuthentication flow

Bots and Connected apps

Device-code bot sign-in, MCP OAuth Connect, bearer keys, Gatekeep invites, and connected app history.

Bots and Connected apps

Bots (agents) sign in on Account with a device code flow or MCP OAuth Connect. Humans own every bot. Connected apps track which first-party apps a person has signed into via handoff, plus MCP client grants.

Three ways to reach Admin MCP

PathWhoHow
Cursor Connect (OAuth)IDE / MCP clientsDiscover PRM on Admin → Auth AS → browser consent → zxoat_ access token
Device codeHeadless botsAccount /api/device/* → human /device → zxmcp_ bot key
Paste bearerManual / legacyAgentic account token from Admin ZiX MCP hub → Authorization: Bearer zxmcp_…

Admin /api/mcp accepts both zxoat_ (OAuth) and zxmcp_ (agent keys). Effective permissions are always scopes/grants ∩ owner RBAC.

MCP OAuth Connect (Auth AS)

Account (auth.ziteox.com) is the shared Authorization Server. Admin is the first Resource Server.

sequenceDiagram
  participant Cursor
  participant Admin as Admin_RS
  participant Auth as Auth_AS
  participant Human

  Cursor->>Admin: GET /api/mcp no token
  Admin-->>Cursor: 401 WWW-Authenticate PRM
  Cursor->>Admin: GET /.well-known/oauth-protected-resource
  Admin-->>Cursor: authorization_servers Auth
  Cursor->>Auth: discovery + DCR + authorize
  Auth->>Human: login MFA consent
  Human-->>Auth: Approve
  Auth-->>Cursor: code then tokens
  Cursor->>Admin: MCP with Bearer zxoat_

Key URLs:

  • Admin PRM: https://admin.ziteox.com/.well-known/oauth-protected-resource
  • Auth AS metadata: https://auth.ziteox.com/.well-known/oauth-authorization-server
  • Authorize / token / register: https://auth.ziteox.com/oauth/*
  • Resource indicator: https://admin.ziteox.com/api/mcp

Tables: core.agent_clients, core.agent_grants, core.oauth_authorization_codes, core.oauth_access_tokens, core.oauth_refresh_tokens.

People can revoke MCP client grants at auth.ziteox.com/account/apps (MCP clients section).

Opting in another product later

  1. Expose MCP on that host (e.g. /api/mcp).
  2. Serve PRM naming Auth as authorization_servers and the product MCP URL as resource.
  3. Make PRM session-optional (no HTML sign-in redirect).
  4. On 401, send WWW-Authenticate with resource_metadata.
  5. Validate zxoat_ with audience = that resource (reuse @ziteox/auth/oauth).

Connecting to Auth alone does not expose Admin tools — each product remains its own MCP resource.

Device code flow (bots)

Bots do not use password login. They use RFC 8628-style device authorization on Account:

  1. Bot calls POST /api/device/code with a client_name and requested scope
  2. Account returns a device_code, a short user_code, and a verification URL
  3. A human opens auth.ziteox.com/device, enters the user code, and approves (two-step / AAL2 required)
  4. Bot polls POST /api/device/token with the device_code until it receives a bearer token once

Approving creates an agent account owned by that human. Bot permissions cannot exceed the owner’s current ceiling.

sequenceDiagram
  participant Bot
  participant Account as Account (auth.ziteox.com)
  participant Human

  Bot->>Account: POST /api/device/code
  Account-->>Bot: device_code, user_code, verification_uri
  Bot->>Account: POST /api/device/token (poll)
  Account-->>Bot: authorization_pending
  Human->>Account: Open /device, enter user_code, approve (AAL2)
  Account->>Account: Provision bot under human owner
  Bot->>Account: POST /api/device/token (poll)
  Account-->>Bot: access_token (bearer, once)

Bot keys and /api/mcp

On successful device poll (or Admin MCP hub issue), Account/Admin issues a bot key: a bearer token used against Admin’s MCP endpoint (/api/mcp).

How checks work (no values — shape only):

  • Tokens are generated with a fixed prefix plus random material; only a SHA-256 hash is stored (mcp_service_tokens / identity token store)
  • Admin validates the Authorization: Bearer … header with resolveMcpAgentAuth → OAuth (zxoat_) or validateAgentToken (zxmcp_)
  • Lookup is by hash; then the code rejects revoked or expired tokens, disabled agents, missing owners, and inactive owners
  • Effective permissions are the agent’s grants capped by the owner’s current permissions
  • Successful use updates last_used_at

Treat bot keys like secrets: show once at issue time, never commit or log the raw value.

Bot invites and Gatekeep

When a bot proposes inviting a client (MCP tool path), Admin does not send email or create an invite row immediately. It opens a Gatekeep approval (invite_client). A human must approve; the executor then issues the invite under the approving person. Staff / admin role invites from bots are blocked.

Connected apps (first-party handoff)

Table core.app_connections (migration 20261101000000_app_connections.sql) records which apps a user has signed into via Account handoff:

ColumnMeaning
user_idAuth user
app_keyApp from core.apps (e.g. admin, client)
first_connected_atFirst successful handoff for that app
last_used_atMost recent successful handoff

On each successful POST /api/handoff/token exchange, Account calls recordAppConnection: insert once (keeps first connected), then bump last_used_at.

People can review the list at auth.ziteox.com/account/apps (first connected and last used per app). That page also links to /device for connecting bots and lists MCP OAuth grants.