feat: API token management in workspace settings
Summary
Workspace-scoped API tokens with a built-in REST API, managed from workspace settings. Tokens are JWTs with configurable expiry (7–365 days) and optional coarse scopes. Expiry and revocation are enforced centrally so the policy is reusable across services.
What changed
API token management (server/account/)
ApiTokentype +apiTokencollection (Mongo + Postgres). Migration V27 createsapi_tokens(including thescopes TEXT[]column).- RPC methods:
createApiToken,listApiTokens,revokeApiToken, plus owner-scopedlistWorkspaceApiTokens/revokeWorkspaceApiToken. - Creation/revocation require
AccountRole.Useror higher (not guests); per-account token cap.
Centralized token verification (server-token) — addresses @aonnikov's review
- New
verifyToken()alongsidedecodeToken(): verifies signature, checks expiry, and — for revokable API tokens — revocation via a pluggable checker (setApiTokenRevocationChecker). Reusable by any service (transactor, blob access, …); the 60s revocation cache now lives here. - The account is authoritative:
wrap()rejects revoked/expired API tokens, so existing methods (selectWorkspace,getWorkspaceInfo, …) naturally return 401. The redundantcheckApiTokenRevokedRPC was removed; the transactor's checker reuses the existinggetLoginInfoByToken.
Scope enforcement (pods/server/src/rpc.ts) — Phase 1
- Coarse scopes
read:*/write:*/delete:*, enforced per method. Scopes are parsed once per request and threaded through (no re-decode in thetxhandler). No scopes = full access (legacy-compatible).
Frontend (plugins/setting-resources/)
ApiTokens.sveltesettings page;ApiTokenCreatePopup.svelte(i18n dropdowns for scope preset + expiry);ApiDocsSection.svelte.- REST base URL is derived from the account-provided transactor endpoint (ws→http), per @aonnikov — not constructed from
window.location.
i18n
- API token strings added and translated across all locales (cs/de/es/fr/it/ja/pt/pt-br/ru/tr/zh). en/ru locale-parity test passes.
Docs
openapi.yamldescribing the REST API.
Test plan
- [x] Unit:
verifyToken(signature/expiry/revocation), scope helpers, scope enforcement, token CRUD. - [ ] Read-only token →
find-allworks,txreturns 403. - [ ] Read & Write →
txworks,TxRemoveDocreturns 403; Full Access → all ops work. - [ ] Legacy token (no scopes) → full access.
- [ ] Revoke a token → rejected within the cache TTL (~60s); account returns 401.
- [ ] V27 migration runs on fresh and existing databases.
Ref: #10622
Connected to Huly®: UBERF-15850
Follow-up: REST API should apply sensible defaults for TxCreateDoc
While testing the token management flow end-to-end (mint token → create issues via REST), I discovered that POST /api/v1/tx/{workspace} passes TxCreateDoc transactions through with zero default-filling. Issues created this way are missing fields that the UI auto-populates, causing them to not appear in project views (only in all-issues).
Missing fields for tracker:class:Issue
When the UI creates an issue, it uses addCollection() which wraps the TxCreateDoc in a TxCollectionCUD, setting:
attachedTo: tracker:ids:NoParentattachedToClass: tracker:class:Issuecollection: "subIssues"
Plus these attributes that get no server-side defaults:
kind→ must betracker:taskTypes:Issue(nottracker:ids:ClassingProjectType)childInfo: [],parents: [],subIssues: 0,comments: 0,reports: 0assignee: null,component: null,dueDate: nullestimation: 0,remainingTime: 0,reportedTime: 0
Impact
Issues created via bare TxCreateDoc (the natural REST usage) are invisible in project views because the Svelte live query filters on attachedTo/collection. They show up in the all-issues aggregated view only.
Possible approaches
- Document it — update REST API docs to show the required
TxCollectionCUDwrapper pattern for issue creation - Server-side defaults middleware — a new middleware in the tx pipeline that merges missing fields from the model schema for known classes (significant arch change)
- Higher-level REST endpoints — add
POST /api/v1/create-issue/{workspace}that accepts a simplified payload and constructs the fullTxCollectionCUDserver-side, like the importer does
Option 3 seems most API-friendly without changing the platform's "caller provides everything" philosophy. Happy to contribute this if there's interest.
Hi @dnplkndll
Thank you for your contribution.
Could you please check formatting for server/account/src/operations.ts?
The corresponding CI step is failed: https://github.com/hcengineering/platform/actions/runs/23164707679/job/67348370400?pr=10624
You can use rush format to format all project files or rushx format for a specific package.
@ArtyomSavchenko Thanks for the review! Formatting has been fixed — the issue was a prettier version mismatch (local 3.8.1 vs project's 3.6.2). New code now matches the existing codebase style with no formatting noise on existing lines.
Changes in this update
3 commits:
feat: API token management— core feature (create/list/revoke tokens, UI, DB, i18n)docs: token scope roadmap— roadmap comments for future scope-based access controlfeat: enforce API token revocation— addresses a gap where revoked tokens remained usable until JWT expiry
What's new since last push
- Token revocation enforcement — the transactor now checks a per-token revocation cache (60s TTL) before granting API access. Revoked tokens are rejected within ~60 seconds instead of remaining valid until expiry.
- Owner-level workspace token visibility — workspace owners can list and revoke any member's API tokens via
listWorkspaceApiTokens/revokeWorkspaceApiToken(OWNER role required). - Ledo instance URL removed —
openapi.yamlnow uses a generichttps://{host}server variable.
Suggestions for future consideration
-
Token scopes — the roadmap commit documents a proposed
extra.scopesJWT field for fine-grained access control (read-only tokens, class-restricted access). This would enable safe MCP/AI agent integrations without MCP-layer changes. -
Higher-level REST endpoints — as noted in my earlier comment,
POST /api/v1/txrequires the caller to construct fullTxCollectionCUDwrappers. APOST /api/v1/create-issuestyle endpoint would make the API much more accessible for integrations. -
Revocation cache scaling — the current per-token cache works well for moderate usage. For high-traffic deployments, a Redis-backed revocation set or short-lived tokens (< 1 hour) with refresh would be more robust.
Hi @dnplkndll Could you please resolve conflicts?
sure what is your opinion on the use of MCP versus api? My motivation was that I would prefer to have tool access in a controlled predicable / scriptable way with permissions on things. then you can test on a staging build out script you can repeat. there are a few things I ran into with the api that the UI handles that should probably be refined, like defaults, too. to simplify not putting records in a bad state.
Thanks for the contribution Overall the idea is great, but need to fix architectural and UI issues.
We also have a button to generate token on workspace settings page, we will need to remove it in favor of the new approach.
Thanks for the reviews — pushed an update addressing the feedback. Conflicts with develop are resolved (merged current develop; the API token migration is renumbered to V27 after develop's V26 pending_configuration).
@aonnikov
- Revocation logic / redundant boolean method: reworked. Token expiry + revocation now live in a new
verifyToken()next todecodeToken()inserver-token, with a pluggable checker (setApiTokenRevocationChecker) so the policy is reusable across services. The account is now authoritative —wrap()rejects revoked/expired API tokens, soselectWorkspace/getWorkspaceInfo/etc. return 401 naturally. The dedicatedcheckApiTokenRevokedRPC is removed; the transactor's checker reuses the existinggetLoginInfoByToken. - Transactor endpoint in
ApiDocsSection: fixed — the REST base URL is now derived from the account-provided transactor endpoint (ws→http), matching theServerManagerGeneralpattern, instead ofwindow.location. - Manual translations in the create popup: it uses
DropdownLabelsIntlwith i18n strings (no hand-rolled translations).
@ArtyomSavchenko
- Role restriction: token creation/revocation now require
AccountRole.Useror higher viaverifyAllowedRole(...)(guests excluded). - Locale tests / untranslated strings: en/ru parity restored and the API token strings are now translated across all locales (cs/de/es/fr/it/ja/pt/pt-br/ru/tr/zh).
- Formatting: re-ran the project formatter;
operations.tsand the scope test are clean.
Unit tests added for verifyToken (signature/expiry/revocation) and scope enforcement. Happy to iterate further.