Repository navigation
feat(auth): use a lone BASE44_ACCESS_TOKEN as an in-memory credential - #681
Open
amitbardos wants to merge 5 commits into
Open
amitbardos wants to merge 5 commits into
amitbardos wants to merge 5 commits into
Conversation
When BASE44_ACCESS_TOKEN is set without BASE44_REFRESH_TOKEN (e.g. the MCP run_command tool injecting a short-lived token into a shared app sandbox for one command), hold it in memory for the current process only: readAuth() returns it ahead of auth.json, it is never written to disk, and refreshAndSaveTokens() returns null without refreshing, writing or deleting auth.json, so on expiry the 401 surfaces. The paired access+refresh path and BASE44_API_KEY precedence 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.3.1-pr.681.965687fPrefer not to change any import paths? Install using npm alias so your code still imports npm i "base44@npm:@base44-preview/cli@0.3.1-pr.681.965687f"Or add it to your {
"dependencies": {
"base44": "npm:@base44-preview/cli@0.3.1-pr.681.965687f"
}
}
Preview published to npm registry — try new features instantly! |
amitbardos
marked this pull request as ready for review
November 5, 2026 11:07
A token in a project .env or .env.local would otherwise authenticate every later command in that directory, which defeats the per-command scope in a shared sandbox. Tokens paired with a refresh token are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
whoami now verifies the session with the server (#688). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bun's standalone executable loads .env from the working directory before the CLI starts, so a token from that file looked like process env. The CLI already loads project env files itself, as the npm build does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
amitbardos
enabled auto-merge (squash)
November 9, 2026 15:03
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_ACCESS_TOKENpreviously only did something when paired withBASE44_REFRESH_TOKEN— the pair was seeded into~/.base44/auth/auth.json, and a lone access token was ignored entirely. This PR makes a lone access token usable as a process-scoped, in-memory credential, for callers like the MCPrun_commandtool that inject a short-lived token into a shared app sandbox for a single command. It is never written to disk, takes precedence overauth.jsonfor that one process, and is only honored when it comes from the real process environment — not from a project.env/.env.local.Related Issue
None
Type of Change
Changes Made
core/auth/config.ts—seedAuthFromEnv()now splits the two cases. With a refresh token the behavior is unchanged (seedauth.json). Without one, a valid JWT (sub+exprequired) is stored in a module-levelenvAccessTokenAuthfor the current process only.readAuth()returns the in-memory credential ahead ofauth.json, so the lone token is the bearer for every request in that command.refreshAndSaveTokens()returnsnullimmediately when an env access token is active — there is nothing to refresh with, andauth.jsonbelongs to someone else, so it is never refreshed, rewritten, or deleted. On expiry the 401 simply surfaces.core/utils/env.ts— records whetherBASE44_ACCESS_TOKEN(bare orBASE44_PROJECTS_-prefixed) was already in the ambient process env before dotenv ran, and exposesisAccessTokenFromEnvFile(). A token sourced from a project env file is rejected for this path, since it would otherwise silently authenticate every later command run in that directory.infra/build-binaries.ts— compile the standalone binaries with--no-compile-autoload-dotenv. Bun autoloads.envintoprocess.envbefore any CLI code runs, which would make a file-sourced token look ambient and defeat the check above. The CLI loads project env files itself, so nothing else changes.docs/api-patterns.md— documents the lone-token path alongside the existing paired-credential seeding.auth.jsonbyte-identical; a 401 triggers no refresh and no deletion; a token from a project.envis ignored; a JWT missingsub/expis ignored. A follow-up commit mocksuserinfoin thewhoamicases, sincewhoaminow verifies the session against the server (fix(auth): verify the session in whoami and fail fast on login without a TTY #688).Testing
npm test)Checklist
docs/(AGENTS.md) if I made architectural changesAdditional Notes
Precedence is unchanged elsewhere:
BASE44_API_KEY(workspace key) still wins, and the pairedBASE44_ACCESS_TOKEN+BASE44_REFRESH_TOKENseeding path behaves exactly as before. The security-relevant invariant is that a lone token never outlives its process and never touches an existing login — both directions are covered by tests. Thelint,typecheck,build, andknipchecks are green; the test matrix was still running when this description was generated, so the testing boxes above are left unchecked.🤖 Generated by Claude | 2026-11-08 15:18 UTC | 965687f