[PR #6350] feat(api-tokens): implement API tokens #40890

Open
opened 2026-04-23 13:41:58 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/actualbudget/actual/pull/6350
Author: @BCNelson
Created: 12/10/2025
Status: 🔄 Open

Base: masterHead: bcn/feat/api-tokens


📝 Commits (10+)

  • 03252d9 feat(api-tokens): implement API token management with creation, listing, revocation, and validation
  • 9c440c1 chore: add tests for API token management endpoints
  • 15d4ac8 release notes
  • 9cd5212 fix: remove unused useTranslation
  • 478c304 lint
  • 047dde6 lint
  • 3f345c4 [autofix.ci] apply automated fixes
  • 834ea92 add API token documentation
  • dcbdec3 fix: genenerating too short tokens
  • 548edbe fix: error handling for API token operations and clipboard

📊 Changes

26 files changed (+2610 additions, -18 deletions)

View changed files

📝 packages/api/index.ts (+8 -0)
packages/desktop-client/src/components/settings/ApiTokens.tsx (+426 -0)
📝 packages/desktop-client/src/components/settings/index.tsx (+2 -0)
📝 packages/docs/docs-sidebar.js (+1 -0)
packages/docs/docs/api/api-tokens.md (+111 -0)
📝 packages/docs/docs/api/index.md (+3 -1)
📝 packages/docs/docs/settings/index.md (+37 -0)
📝 packages/loot-core/bin/build-api (+1 -1)
📝 packages/loot-core/bin/build-browser (+2 -1)
📝 packages/loot-core/bin/copy-migrations (+2 -1)
📝 packages/loot-core/src/server/auth/app.ts (+163 -1)
📝 packages/loot-core/src/server/errors.ts (+46 -0)
📝 packages/loot-core/src/server/main.ts (+27 -1)
packages/sync-server/migrations/1733782800000-create-api-tokens.js (+52 -0)
📝 packages/sync-server/src/app-account.js (+15 -6)
📝 packages/sync-server/src/app-admin.js (+4 -4)
packages/sync-server/src/app-api-tokens.test.js (+396 -0)
packages/sync-server/src/app-api-tokens.ts (+285 -0)
📝 packages/sync-server/src/app-sync.ts (+2 -0)
📝 packages/sync-server/src/app.ts (+2 -0)

...and 6 more files

📄 Description

This pull request introduces support for API tokens, enabling users to programmatically access their budgets via the Actual API. The changes span the desktop client, core authentication logic, error handling, and server/database layers. Users can now create, list, revoke, and update API tokens in the settings UI, and the backend supports secure storage and management of these tokens.

API Token Management Functionality

  • Added API token management handlers (listApiTokens, createApiToken, revokeApiToken, updateApiToken) to loot-core/src/server/auth/app.ts, including new types ApiToken and ApiTokenCreateResult and their registration in the app’s handler map. [1] [2] [3]
  • Created a new settings UI component ApiTokensSettings in desktop-client/src/components/settings/ApiTokens.tsx for users to manage API tokens: create, view, revoke, and copy tokens, with appropriate modals and error handling.
  • Integrated the new API tokens settings into the main settings page by importing and rendering ApiTokensSettings. [1] [2]

Authentication and Error Handling

  • Defined new authentication error classes (AuthError, TokenExpiredError, InvalidTokenError, TokenScopeError) in loot-core/src/server/errors.ts and exported them for use in API token workflows. [1] [2]
  • Updated the API initialization logic in loot-core/src/server/main.ts to support authentication via API token, validate tokens, and ensure only one authentication method (password or token) is used. [1] [2]

Database Schema Changes

  • Added a new migration to the sync server (migrations/1733782800000-create-api-tokens.js) to create api_tokens and api_token_budgets tables, supporting secure storage of tokens and their budget scopes.

Bundle Stats

Bundle Files count Total bundle size % Changed
desktop-client 27 14.85 MB → 14.87 MB (+21.1 kB) +0.14%
loot-core 1 5.82 MB → 5.82 MB (+4.83 kB) +0.08%
api 1 4.43 MB → 4.44 MB (+4.23 kB) +0.09%
View detailed bundle stats

desktop-client

Total

Files count Total bundle size % Changed
27 14.85 MB → 14.87 MB (+21.1 kB) +0.14%
Changeset
File Δ Size
src/components/settings/ApiTokens.tsx 🆕 +20.97 kB 0 B → 20.97 kB
src/components/settings/index.tsx 📈 +128 B (+1.09%) 11.45 kB → 11.58 kB
src/components/rules/RuleEditor.tsx 📈 +2 B (+0.00%) 49.43 kB → 49.43 kB
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 9.54 MB → 9.56 MB (+21.1 kB) +0.22%

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
static/js/indexeddb-main-thread-worker-e59fee74.js 12.94 kB 0%
static/js/workbox-window.prod.es5.js 5.64 kB 0%
static/js/ca.js 188.15 kB 0%
static/js/da.js 106.35 kB 0%
static/js/de.js 180.07 kB 0%
static/js/en-GB.js 7.18 kB 0%
static/js/en.js 170.37 kB 0%
static/js/es.js 174.55 kB 0%
static/js/fr.js 179.6 kB 0%
static/js/it.js 171.16 kB 0%
static/js/nb-NO.js 156.96 kB 0%
static/js/nl.js 106.37 kB 0%
static/js/pl.js 88.37 kB 0%
static/js/pt-BR.js 154.22 kB 0%
static/js/th.js 181.87 kB 0%
static/js/uk.js 214.74 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/BackgroundImage.js 120.54 kB 0%
static/js/ReportRouter.js 1.16 MB 0%
static/js/narrow.js 637.77 kB 0%
static/js/TransactionList.js 106.22 kB 0%
static/js/wide.js 164.15 kB 0%
static/js/AppliedFilters.js 9.71 kB 0%
static/js/usePayeeRuleCounts.js 10.04 kB 0%
static/js/useTransactionBatchActions.js 13.23 kB 0%
static/js/FormulaEditor.js 1.04 MB 0%

loot-core

Total

Files count Total bundle size % Changed
1 5.82 MB → 5.82 MB (+4.83 kB) +0.08%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/loot-core/src/server/auth/app.ts 📈 +3.54 kB (+44.73%) 7.92 kB → 11.46 kB
home/runner/work/actual/actual/packages/loot-core/src/server/errors.ts 📈 +703 B (+43.08%) 1.59 kB → 2.28 kB
home/runner/work/actual/actual/packages/loot-core/src/server/main.ts 📈 +613 B (+10.04%) 5.96 kB → 6.56 kB
View detailed bundle breakdown

Added

Asset File Size % Changed
kcab.worker.qKSwmiGS.js 0 B → 5.82 MB (+5.82 MB) -

Removed

Asset File Size % Changed
kcab.worker.C2vnwNMt.js 5.82 MB → 0 B (-5.82 MB) -100%

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged
No assets were unchanged


api

Total

Files count Total bundle size % Changed
1 4.43 MB → 4.44 MB (+4.23 kB) +0.09%
Changeset
File Δ Size
src/server/auth/app.ts 📈 +3.09 kB (+45.35%) 6.81 kB → 9.9 kB
src/server/errors.ts 📈 +607 B (+43.86%) 1.35 kB → 1.94 kB
src/server/main.ts 📈 +561 B (+10.61%) 5.17 kB → 5.71 kB
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger

Asset File Size % Changed
bundle.api.js 4.43 MB → 4.44 MB (+4.23 kB) +0.09%

Smaller
No assets were smaller

Unchanged
No assets were unchanged


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/actualbudget/actual/pull/6350 **Author:** [@BCNelson](https://github.com/BCNelson) **Created:** 12/10/2025 **Status:** 🔄 Open **Base:** `master` ← **Head:** `bcn/feat/api-tokens` --- ### 📝 Commits (10+) - [`03252d9`](https://github.com/actualbudget/actual/commit/03252d9e4a2b34118da13a2a9d800230b97600c6) feat(api-tokens): implement API token management with creation, listing, revocation, and validation - [`9c440c1`](https://github.com/actualbudget/actual/commit/9c440c160097f872500659c73983ddd9375b0bf8) chore: add tests for API token management endpoints - [`15d4ac8`](https://github.com/actualbudget/actual/commit/15d4ac84f4806f03274671a81e2919c707626ff1) release notes - [`9cd5212`](https://github.com/actualbudget/actual/commit/9cd5212568192d57e7a5be90884388dfee43b0c2) fix: remove unused useTranslation - [`478c304`](https://github.com/actualbudget/actual/commit/478c3046b3641ccad001c0676b587127e533e257) lint - [`047dde6`](https://github.com/actualbudget/actual/commit/047dde6edd30f2f19703c72ce1f6beff39198045) lint - [`3f345c4`](https://github.com/actualbudget/actual/commit/3f345c4d4bb862ce53c7b91e272ae619b5738f29) [autofix.ci] apply automated fixes - [`834ea92`](https://github.com/actualbudget/actual/commit/834ea928e460053864cb4335016d1055f3b9e9dd) add API token documentation - [`dcbdec3`](https://github.com/actualbudget/actual/commit/dcbdec3a07e2f7ecb3178c96c2ba6470a568c4f1) fix: genenerating too short tokens - [`548edbe`](https://github.com/actualbudget/actual/commit/548edbe49e645565a5dde1a5c86e6a90aa7ab3b0) fix: error handling for API token operations and clipboard ### 📊 Changes **26 files changed** (+2610 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `packages/api/index.ts` (+8 -0) ➕ `packages/desktop-client/src/components/settings/ApiTokens.tsx` (+426 -0) 📝 `packages/desktop-client/src/components/settings/index.tsx` (+2 -0) 📝 `packages/docs/docs-sidebar.js` (+1 -0) ➕ `packages/docs/docs/api/api-tokens.md` (+111 -0) 📝 `packages/docs/docs/api/index.md` (+3 -1) 📝 `packages/docs/docs/settings/index.md` (+37 -0) 📝 `packages/loot-core/bin/build-api` (+1 -1) 📝 `packages/loot-core/bin/build-browser` (+2 -1) 📝 `packages/loot-core/bin/copy-migrations` (+2 -1) 📝 `packages/loot-core/src/server/auth/app.ts` (+163 -1) 📝 `packages/loot-core/src/server/errors.ts` (+46 -0) 📝 `packages/loot-core/src/server/main.ts` (+27 -1) ➕ `packages/sync-server/migrations/1733782800000-create-api-tokens.js` (+52 -0) 📝 `packages/sync-server/src/app-account.js` (+15 -6) 📝 `packages/sync-server/src/app-admin.js` (+4 -4) ➕ `packages/sync-server/src/app-api-tokens.test.js` (+396 -0) ➕ `packages/sync-server/src/app-api-tokens.ts` (+285 -0) 📝 `packages/sync-server/src/app-sync.ts` (+2 -0) 📝 `packages/sync-server/src/app.ts` (+2 -0) _...and 6 more files_ </details> ### 📄 Description This pull request introduces support for API tokens, enabling users to programmatically access their budgets via the Actual API. The changes span the desktop client, core authentication logic, error handling, and server/database layers. Users can now create, list, revoke, and update API tokens in the settings UI, and the backend supports secure storage and management of these tokens. **API Token Management Functionality** * Added API token management handlers (`listApiTokens`, `createApiToken`, `revokeApiToken`, `updateApiToken`) to `loot-core/src/server/auth/app.ts`, including new types `ApiToken` and `ApiTokenCreateResult` and their registration in the app’s handler map. [[1]](diffhunk://#diff-c1040f700226b4a3888372f04be84ef64420a622b71c71099eedbd8b02d9110fR23-R26) [[2]](diffhunk://#diff-c1040f700226b4a3888372f04be84ef64420a622b71c71099eedbd8b02d9110fR42-R45) [[3]](diffhunk://#diff-c1040f700226b4a3888372f04be84ef64420a622b71c71099eedbd8b02d9110fR394-R560) * Created a new settings UI component `ApiTokensSettings` in `desktop-client/src/components/settings/ApiTokens.tsx` for users to manage API tokens: create, view, revoke, and copy tokens, with appropriate modals and error handling. * Integrated the new API tokens settings into the main settings page by importing and rendering `ApiTokensSettings`. [[1]](diffhunk://#diff-a3a629c5957c0a86a602bd8e2afd8eb0cbcdebfcd66183367f349557a6d19fcfR16) [[2]](diffhunk://#diff-a3a629c5957c0a86a602bd8e2afd8eb0cbcdebfcd66183367f349557a6d19fcfR251) **Authentication and Error Handling** * Defined new authentication error classes (`AuthError`, `TokenExpiredError`, `InvalidTokenError`, `TokenScopeError`) in `loot-core/src/server/errors.ts` and exported them for use in API token workflows. [[1]](diffhunk://#diff-61b0e157b383d2f773f0973fd09ecc02f3266dedaed16cd0297e6eb69d16f8d8R106-R147) [[2]](diffhunk://#diff-b2e10ba3ec9d68a47ac13e3a3c67d2d818e249202c887a5d5d9869aece17b376R21-R28) * Updated the API initialization logic in `loot-core/src/server/main.ts` to support authentication via API token, validate tokens, and ensure only one authentication method (password or token) is used. [[1]](diffhunk://#diff-c9b9c2688ecbd5ed8814e71d09f631d2bece3b987ba9b4a04e06cfe07e1b27f2R234) [[2]](diffhunk://#diff-c9b9c2688ecbd5ed8814e71d09f631d2bece3b987ba9b4a04e06cfe07e1b27f2L261-R285) **Database Schema Changes** * Added a new migration to the sync server (`migrations/1733782800000-create-api-tokens.js`) to create `api_tokens` and `api_token_budgets` tables, supporting secure storage of tokens and their budget scopes. <!--- actual-bot-sections ---> <hr /> <!--- bundlestats-action-comment key:combined start ---> ### Bundle Stats Bundle | Files count | Total bundle size | % Changed ------ | ----------- | ----------------- | --------- desktop-client | 27 | 14.85 MB → 14.87 MB (+21.1 kB) | +0.14% loot-core | 1 | 5.82 MB → 5.82 MB (+4.83 kB) | +0.08% api | 1 | 4.43 MB → 4.44 MB (+4.23 kB) | +0.09% <details> <summary>View detailed bundle stats</summary> #### desktop-client **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 27 | 14.85 MB → 14.87 MB (+21.1 kB) | +0.14% <details> <summary>Changeset</summary> File | Δ | Size ---- | - | ---- `src/components/settings/ApiTokens.tsx` | 🆕 +20.97 kB | 0 B → 20.97 kB `src/components/settings/index.tsx` | 📈 +128 B (+1.09%) | 11.45 kB → 11.58 kB `src/components/rules/RuleEditor.tsx` | 📈 +2 B (+0.00%) | 49.43 kB → 49.43 kB </details> <details> <summary>View detailed bundle breakdown</summary> <div> **Added** No assets were added **Removed** No assets were removed **Bigger** Asset | File Size | % Changed ----- | --------- | --------- static/js/index.js | 9.54 MB → 9.56 MB (+21.1 kB) | +0.22% **Smaller** No assets were smaller **Unchanged** Asset | File Size | % Changed ----- | --------- | --------- static/js/indexeddb-main-thread-worker-e59fee74.js | 12.94 kB | 0% static/js/workbox-window.prod.es5.js | 5.64 kB | 0% static/js/ca.js | 188.15 kB | 0% static/js/da.js | 106.35 kB | 0% static/js/de.js | 180.07 kB | 0% static/js/en-GB.js | 7.18 kB | 0% static/js/en.js | 170.37 kB | 0% static/js/es.js | 174.55 kB | 0% static/js/fr.js | 179.6 kB | 0% static/js/it.js | 171.16 kB | 0% static/js/nb-NO.js | 156.96 kB | 0% static/js/nl.js | 106.37 kB | 0% static/js/pl.js | 88.37 kB | 0% static/js/pt-BR.js | 154.22 kB | 0% static/js/th.js | 181.87 kB | 0% static/js/uk.js | 214.74 kB | 0% static/js/resize-observer.js | 18.37 kB | 0% static/js/BackgroundImage.js | 120.54 kB | 0% static/js/ReportRouter.js | 1.16 MB | 0% static/js/narrow.js | 637.77 kB | 0% static/js/TransactionList.js | 106.22 kB | 0% static/js/wide.js | 164.15 kB | 0% static/js/AppliedFilters.js | 9.71 kB | 0% static/js/usePayeeRuleCounts.js | 10.04 kB | 0% static/js/useTransactionBatchActions.js | 13.23 kB | 0% static/js/FormulaEditor.js | 1.04 MB | 0% </div> </details> --- #### loot-core **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 1 | 5.82 MB → 5.82 MB (+4.83 kB) | +0.08% <details> <summary>Changeset</summary> File | Δ | Size ---- | - | ---- `home/runner/work/actual/actual/packages/loot-core/src/server/auth/app.ts` | 📈 +3.54 kB (+44.73%) | 7.92 kB → 11.46 kB `home/runner/work/actual/actual/packages/loot-core/src/server/errors.ts` | 📈 +703 B (+43.08%) | 1.59 kB → 2.28 kB `home/runner/work/actual/actual/packages/loot-core/src/server/main.ts` | 📈 +613 B (+10.04%) | 5.96 kB → 6.56 kB </details> <details> <summary>View detailed bundle breakdown</summary> <div> **Added** Asset | File Size | % Changed ----- | --------- | --------- kcab.worker.qKSwmiGS.js | 0 B → 5.82 MB (+5.82 MB) | - **Removed** Asset | File Size | % Changed ----- | --------- | --------- kcab.worker.C2vnwNMt.js | 5.82 MB → 0 B (-5.82 MB) | -100% **Bigger** No assets were bigger **Smaller** No assets were smaller **Unchanged** No assets were unchanged </div> </details> --- #### api **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 1 | 4.43 MB → 4.44 MB (+4.23 kB) | +0.09% <details> <summary>Changeset</summary> File | Δ | Size ---- | - | ---- `src/server/auth/app.ts` | 📈 +3.09 kB (+45.35%) | 6.81 kB → 9.9 kB `src/server/errors.ts` | 📈 +607 B (+43.86%) | 1.35 kB → 1.94 kB `src/server/main.ts` | 📈 +561 B (+10.61%) | 5.17 kB → 5.71 kB </details> <details> <summary>View detailed bundle breakdown</summary> <div> **Added** No assets were added **Removed** No assets were removed **Bigger** Asset | File Size | % Changed ----- | --------- | --------- bundle.api.js | 4.43 MB → 4.44 MB (+4.23 kB) | +0.09% **Smaller** No assets were smaller **Unchanged** No assets were unchanged </div> </details> </details> <!--- bundlestats-action-comment key:combined end ---> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-23 13:41:58 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#40890