-
Notifications
You must be signed in to change notification settings - Fork 12
fix: Swap stored password for Matrix access token (CS-10725) #4779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
435f1e3
4619020
9eacab2
06f26c1
a26daca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,7 +80,7 @@ function validateUrl(input: string, label: string): string { | |
|
|
||
| // Matches scripts/env-slug.sh: lowercase, "/" -> "-", strip chars outside | ||
| // [a-z0-9-], collapse runs of "-", trim leading/trailing "-". | ||
| function computeEnvSlug(name: string): string { | ||
| export function computeEnvSlug(name: string): string { | ||
| return name | ||
| .toLowerCase() | ||
| .replace(/\//g, '-') | ||
|
|
@@ -91,7 +91,7 @@ function computeEnvSlug(name: string): string { | |
|
|
||
| // Derive URLs from BOXEL_ENVIRONMENT using the same ".${slug}.localhost" | ||
| // pattern that mise-tasks/lib/env-vars.sh produces for env-mode local dev. | ||
| function resolveBoxelEnvironment(): EnvironmentDefaults | null { | ||
| export function resolveBoxelEnvironment(): EnvironmentDefaults | null { | ||
| const raw = process.env.BOXEL_ENVIRONMENT; | ||
| if (!raw || !raw.trim()) return null; | ||
| const slug = computeEnvSlug(raw); | ||
|
|
@@ -458,14 +458,28 @@ async function addProfileNonInteractive( | |
| process.exit(1); | ||
| } | ||
|
|
||
| if (manager.getProfile(matrixId)) { | ||
| console.log( | ||
| `${FG_YELLOW}Profile ${matrixId} already exists. Updating password.${RESET}`, | ||
| const isUpdate = Boolean(manager.getProfile(matrixId)); | ||
|
|
||
| // addProfile performs a real matrixLogin and persists the resulting | ||
| // access token (the password never lands on disk). It also handles the | ||
| // create-vs-reauth split uniformly: re-running it on an existing profile | ||
| // refreshes the stored token while preserving cached realm tokens. | ||
| try { | ||
| await manager.addProfile( | ||
| matrixId, | ||
| password, | ||
| displayName, | ||
| matrixUrl, | ||
| realmServerUrl, | ||
| ); | ||
|
Comment on lines
+461
to
474
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in e830ad1. |
||
| await manager.updatePassword(matrixId, password); | ||
| if (displayName) { | ||
| manager.updateDisplayName(matrixId, displayName); | ||
| } | ||
| } catch (err) { | ||
| console.error( | ||
| `${FG_RED}Error:${RESET} ${err instanceof Error ? err.message : String(err)}`, | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| if (isUpdate) { | ||
| if (matrixUrl || realmServerUrl) { | ||
| const urlsChanged = manager.updateUrls(matrixId, { | ||
| matrixUrl, | ||
|
|
@@ -483,20 +497,6 @@ async function addProfileNonInteractive( | |
| return; | ||
| } | ||
|
|
||
| try { | ||
| await manager.addProfile( | ||
| matrixId, | ||
| password, | ||
| displayName, | ||
| matrixUrl, | ||
| realmServerUrl, | ||
| ); | ||
| } catch (err) { | ||
| console.error( | ||
| `${FG_RED}Error:${RESET} ${err instanceof Error ? err.message : String(err)}`, | ||
| ); | ||
| process.exit(1); | ||
| } | ||
| console.log( | ||
| `${FG_GREEN}\u2713${RESET} Profile created: ${formatProfileBadge(matrixId)}`, | ||
| ); | ||
|
|
@@ -538,7 +538,7 @@ async function migrateFromEnv(manager: ProfileManager): Promise<void> { | |
| ); | ||
| } else { | ||
| console.log( | ||
| `${FG_YELLOW}Profile ${formatProfileBadge(result.profileId)} already exists.${RESET} Password has been updated if it changed.`, | ||
| `${FG_GREEN}\u2713${RESET} Refreshed profile: ${formatProfileBadge(result.profileId)}`, | ||
| ); | ||
| console.log( | ||
| `\n${DIM}Use 'boxel profile add -u ${result.profileId} -p <password>' to update other fields.${RESET}`, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
profile addupdates an existing profile, this now callsmanager.addProfile(...)beforeupdateUrls(...).addProfileWithAuthpreserves the previousrealmTokensandrealmServerToken, and because URLs have already been rewritten by the timeupdateUrlsruns, it sees no change and does not clear those caches. That leaves tokens minted for the old server in the profile; code paths likerealm createthat usegetOrRefreshServerToken()+fetchAndStoreRealmToken()without an automatic 401 retry can fail or silently skip token acquisition after a URL change.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in e830ad1.
addProfileWithAuthnow compares the resolved URLs against the existing profile and clearsrealmTokens/realmServerTokenwhen either URL changes. Independently,addProfiledefaults omitted URL args to the existing profile so the no-flag re-auth path no longer rewrites URLs at all.