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

Open
opened 2026-04-14 21:46:17 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/actualbudget/actual/pull/6350

State: open
Merged: No


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

**Original Pull Request:** https://github.com/actualbudget/actual/pull/6350 **State:** open **Merged:** No --- 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 --->
GiteaMirror added the pull-request label 2026-04-14 21:46:17 -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#20822