Repository navigation
feat(api): send an app-user token to app-user-only operations in api fetch - #689
Closed
NitzanSirota wants to merge 1 commit into
Closed
NitzanSirota wants to merge 1 commit into
NitzanSirota wants to merge 1 commit into
Conversation
…fetch App runtime routes (entities, User, count, trash) only understand app-user tokens; the platform login was read as anonymous, giving wrong or empty results with no error. When the spec marks the matched operation with the AppUserTokenAuth scheme and the CLI runs on a platform login, exchange it via getAppUserToken (as exec does) and send that instead. Workspace API keys and specs without the scheme are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
🚀 Package Preview Available!Install this PR's preview build with npm: npm i @base44-preview/cli@0.2.7-pr.689.072f10aPrefer not to change any import paths? Install using npm alias so your code still imports npm i "base44@npm:@base44-preview/cli@0.2.7-pr.689.072f10a"Or add it to your {
"dependencies": {
"base44": "npm:@base44-preview/cli@0.2.7-pr.689.072f10a"
}
}
Preview published to npm registry — try new features instantly! |
NitzanSirota
marked this pull request as ready for review
November 2, 2026 06:16
NitzanSirota
marked this pull request as draft
November 2, 2026 08:39
Author
|
Superseded by base44-dev/apper#36893: the server now runs a CLI token as the caller's app user on app routes, so the client-side exchange isn't needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Description
base44 api fetchsent the platform login token to every route, including app runtime routes (entities,User, count, trash) that only understand an app user's token — so the server treated those calls as anonymous and returned empty or wrong results with no error. This PR teachesapi fetchto read theAppUserTokenAuthsecurity scheme from the API spec and, for operations marked with it, exchange the platform login for an app-user token viaGET /api/apps/{app_id}/auth/token(the same flowbase44 execalready uses) before sending the request. Workspace API keys, unmarked operations, non-app paths, and older servers whose spec lacks the scheme all behave exactly as before.Related Issue
None. Depends on the spec change in base44-dev/apper#36784, which adds the
AppUserTokenAuthscheme to the marked operations.Type of Change
Changes Made
core/api-spec/operations.ts— parse theAppUserTokenAuthsecurity scheme into a newApiOperation.appUserTokenflag (operation-levelsecurity, falling back to the spec-level default), and addpathParameter()to read a concrete path's value for a{name}segment of the matched operation's template.core/api-spec/request.ts— addappUserTokenFor(method, path, { refresh }): short-circuits on a workspace API key or a non-/api/apps/{id}/path, loads and matches the spec, and exchanges for an app-user token only when the matched operation is marked. A spec that fails to load is swallowed (.catch(() => null)) so an older server falls back to sending the login as before.sendApiRequest()takes an optionalappUserTokenand routes through the app-user client when present.core/clients/base44-client.ts— newgetAppUserClient(token)ky factory that sendsAuthorization: Bearer <app-user-token>, keepsX-Request-IDand request-body capture, and deliberately omits the refresh-on-401 hook (a retry with the platform login would just run as anonymous again). Exported fromcore/clients/index.ts.core/project/api.ts—getAppUserToken()now accepts an optionalappId(defaulting togetAppContext().id) and callsbase44Clientwith an explicitapi/apps/{appId}/auth/tokenpath instead ofgetAppClient(), so it works for an app id taken from the request path without requiring initialized app context.cli/commands/api/fetch.ts— resolve the app-user token inside therunTaskcallback before sending, passingrefresh: options.refresh && !options.readOnlyto avoid re-fetching a spec that--read-onlyalready refreshed.CHANGELOG.md— entry underChangeddescribing the new behaviour.Testing
npm test)New
app user tokensuite inpackages/cli/tests/cli/api.spec.tscovering the three paths, with the spec fixture extended to markGET /api/apps/{app_id}/entities/{entity_name}withAppUserTokenAuth:app_id) and sendsBearer app-user-token;/api/apps/68a1/workflows/runs) performs no exchange and sends the login;BASE44_API_KEY) performs no exchange and is sent as theapi_keyheader with noAuthorization.The marked-operation test also asserts the exchanged token never appears in stdout or stderr. The
specFetches === 0assertion moved to the test where it still holds, since resolving the token now consults the cached spec.Checklist
docs/(AGENTS.md) if I made architectural changesAdditional Notes
X-Bypass-RLSheader is sent: the call runs as the caller's app user under the app's own access rules, not with elevated privileges.dev.spec.tsDeno-fallback test, which also fails onmainwhen Deno is not installed.docs/was not updated — the change adds a client factory and a spec-driven auth branch rather than altering documented architecture — but reviewers may wantdocs/api-patterns.mdto mentiongetAppUserClientalongsidebase44Client/getAppClient.🤖 Generated by Claude | 2026-11-02 06:07 UTC | 072f10a