feat: API token management in workspace settings#10624
feat: API token management in workspace settings#10624dnplkndll wants to merge 5 commits intohcengineering:developfrom
Conversation
|
Connected to Huly®: UBERF-15850 |
c84d786 to
efdbe1b
Compare
Follow-up: REST API should apply sensible defaults for
|
c7d2bf2 to
aaa8348
Compare
|
Hi @dnplkndll |
8663ec8 to
865fd71
Compare
|
@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 update3 commits:
What's new since last push
Suggestions for future consideration
|
Add UI and backend support for creating, listing, and revoking API tokens scoped to workspaces. Includes owner-level workspace token visibility, OpenAPI documentation, Mongo/Postgres persistence, and i18n translations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Don Kendall <kendall@donkendall.com>
4e76ecd to
377fd42
Compare
Embed apiTokenId in JWT extra field and add a per-token revocation cache (60s TTL) in the transactor REST handler. Revoked tokens are now rejected within ~60 seconds instead of remaining valid until JWT expiry. Adds checkApiTokenRevoked account service method for the transactor to query individual token revocation status. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Don Kendall <kendall@donkendall.com>
Add coarse-grained scope enforcement for API tokens. Tokens can now be created with scopes ['read:*'], ['read:*','write:*'], or ['read:*','write:*','delete:*']. Existing tokens without scopes retain full access (backward compatible). - DB: v26 migration adds scopes TEXT[] column to api_tokens - Types: add scopes field to ApiToken and ApiTokenInfo - Operations: createApiToken accepts/validates/persists scopes, embeds in JWT via extra.scopes - Enforcement: withSession checks scopes against method; tx handler additionally requires delete:* for TxRemoveDoc - Client: createApiToken signature accepts optional scopes param - UI: scope preset dropdown in create popup (default: Read Only), permissions column in token list with i18n labels - Also fixes 3 pre-existing TS2322/TS2345 errors in operations.ts Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Don Kendall <kendall@donkendall.com>
- scopes.test.ts: 8 tests for hasScope() and getRequiredScope() logic - apiTokenScopes.test.ts: 7 tests for createApiToken scope validation (valid scopes, multiple scopes, no scopes backward compat, invalid format rejection, empty array rejection, domain-scope rejection) and listApiTokens scopes inclusion - Export hasScope/getRequiredScope from rpc.ts for testability Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Don Kendall <kendall@donkendall.com>
c39720c to
058c7da
Compare
…tting - Restrict API token creation/revocation to AccountRole.User or higher (guests cannot use API tokens), per reviewer suggestion - Add 5 missing translation keys (ApiTokenPermissions, ApiTokenScopePreset, ApiTokenScopeReadOnly, ApiTokenScopeReadWrite, ApiTokenScopeFullAccess) to all non-en locale files to fix locale parity CI test - Fix prettier formatting in apiTokenScopes.test.ts - Rename local `extra` to `tokenExtra` in createApiToken to avoid shadowing the decoded token's `extra` field Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Don Kendall <kendall@donkendall.com>
|
|
||
| import { AccountRole, type MeasureContext, type PersonUuid, type WorkspaceUuid } from '@hcengineering/core' | ||
| import platform, { PlatformError, Severity, Status } from '@hcengineering/platform' | ||
| import { decodeTokenVerbose, generateToken } from '@hcengineering/server-token' |
There was a problem hiding this comment.
Could you please check warnings in this file?
CI formatting step is failed due to this:
https://github.com/hcengineering/platform/actions/runs/23317689234/job/67851578625?pr=10624
Summary
api_tokenstableread:*,write:*,delete:*with server-side enforcementcreateApiToken,listApiTokens,revokeApiTokenaccount service RPC methodsChanges
Backend (
server/account/):ApiTokentype withscopes?: string[]+apiTokenDB collectionapi_tokenstable; V26 migration:scopes TEXT[]columnAccountMethodsandgetMethods()createApiTokenvalidates scopes, embeds in JWTextra.scopes, persists to DBAccountClientinterface + implementation extended with optionalscopesparamScope Enforcement (
pods/server/src/rpc.ts):withSession()checksdecodedToken.extra.scopesagainst method requirementsread:*required for find-all, search, load-model, accountwrite:*required for tx (create/update), domain requests, ensure-persondelete:*additionally required forTxRemoveDoctransactionsFrontend (
plugins/setting-resources/):ApiTokens.svelte— workspace settings page with permissions column (i18n)ApiTokenCreatePopup.svelte— creation modal with scope preset dropdown (default: Read Only)WorkspaceSettingCategoryin the modelAlso:
operations.tsTest plan
Ref: #10622
🤖 Generated with Claude Code