Repository navigation
fix(auth): auth logout removes the saved Altimate gateway key
#1606
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
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 |
|---|---|---|
|
|
@@ -43,6 +43,8 @@ Managed LLM access with dynamic routing across Sonnet 4.6, Opus 4.6, GPT-5.4, GP | |
|
|
||
| For pricing, security, and data handling details, see the [Altimate LLM Gateway guide](https://help.altimate.ai/datamates/user-guide/components/llm-gateway/). | ||
|
|
||
| To sign out, run `altimate providers logout altimate-backend` (or `/logout` in the TUI). This removes the saved key from `~/.altimate/altimate.json` and the auth store, so workspace requests stop until you sign in again. | ||
|
Collaborator
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. Minor (not a blocker, pre-existing): logout deletes the whole
Collaborator
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. Minor (not a blocker, cosmetic): on Windows the file is |
||
|
|
||
| !!! tip "Automatic model selection" | ||
| When Altimate credentials are configured and no model is explicitly chosen, the Altimate LLM Gateway is selected automatically. You can override this by setting `model` in your config or by restricting the `provider` section to specific providers only. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ import type { Hooks } from "@opencode-ai/plugin" | |
| import { Process } from "@/util/process" | ||
| import { errorMessage } from "@/util/error" | ||
| import { FreeTier } from "@/altimate/free/client" | ||
| import { AltimateApi } from "@/altimate/api/client" | ||
| import { text } from "node:stream/consumers" | ||
| import { Effect, Option } from "effect" | ||
|
|
||
|
|
@@ -605,6 +606,14 @@ export const ProvidersLogoutCommand = effectCmd({ | |
| label: (database[key]?.name || key) + UI.Style.TEXT_DIM + " (" + value.type + ")", | ||
| value: key, | ||
| })) | ||
| // Credentials saved only to ~/.altimate/altimate.json (TUI paste dialog) have no auth-store entry. | ||
| const hasAltimateBackendFile = yield* Effect.promise(() => AltimateApi.isConfigured()) | ||
| if (hasAltimateBackendFile && !options.some((option) => option.value === "altimate-backend")) { | ||
| options.push({ | ||
| label: (database["altimate-backend"]?.name || "altimate-backend") + UI.Style.TEXT_DIM + " (api)", | ||
| value: "altimate-backend", | ||
| }) | ||
| } | ||
| if (hasAltimateBaseCredential || hasLegacyAltimateBaseCredential || hasAltimateBaseState) { | ||
| options.push({ | ||
| label: "Altimate Base" + UI.Style.TEXT_DIM + " (managed)", | ||
|
|
@@ -638,6 +647,11 @@ export const ProvidersLogoutCommand = effectCmd({ | |
| yield* Prompt.outro("Logout successful") | ||
| return | ||
| } | ||
| if (provider === "altimate-backend") { | ||
|
Collaborator
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. Major: datamate MCP entries keep the gateway key on disk and keep authenticating after logout In standalone/CLI mode, Suggested fix: on |
||
| // Browser sign-in persists the gateway key to ~/.altimate/altimate.json, which the provider | ||
| // loader and every workspace call read first, so sign-out must remove it too. | ||
| yield* cliTry("Failed to remove Altimate credential: ", () => AltimateApi.clearCredentials()) | ||
|
Collaborator
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. Minor (not a blocker): a failed clear stops the logout, and the message gives no next step If Suggestion: include the file path and a "delete it manually" hint in the message. Optionally, still remove the auth-store entry and report the partial failure. |
||
| } | ||
| // altimate_change end | ||
| yield* Effect.orDie(authSvc.remove(provider)) | ||
| yield* Prompt.outro("Logout successful") | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -87,6 +87,8 @@ function show(api: TuiPluginApi) { | |||||||
| async function logout(api: TuiPluginApi) { | ||||||||
| try { | ||||||||
| await AltimateApi.clearCredentials() | ||||||||
| // A pasted url::instance::key in the auth store keeps the provider loader's fallback path live. | ||||||||
| await api.client.auth.remove({ providerID: PROVIDER_ID }) | ||||||||
|
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. P2: This Prompt for AI agents
Suggested change
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. Fail sign-out when auth removal fails. If the server rejects this request, the SDK resolves with an Based on learnings, sign-out must invalidate every usable credential fallback.
|
||||||||
| await api.client.instance.dispose() | ||||||||
| api.ui.toast({ variant: "success", message: "Signed out of Altimate LLM Gateway" }) | ||||||||
| } catch (err) { | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,4 +97,60 @@ describe("providers logout", () => { | |
| }), | ||
| 120_000, | ||
| ) | ||
|
|
||
| cliIt.live( | ||
|
Collaborator
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. Minor (not a blocker, test-only): add failure-path and TUI coverage This test does fail on
|
||
| "removes the saved Altimate gateway key along with the auth-store entry", | ||
| ({ home, opencode }) => | ||
| Effect.gen(function* () { | ||
| const dataDir = path.join(home, ".local", "share", "altimate-code") | ||
| const authPath = path.join(dataDir, "auth.json") | ||
| const altimatePath = path.join(home, ".altimate", "altimate.json") | ||
| const anthropic = { type: "api", key: "anthropic-test-key" } | ||
| const writeAltimate = () => | ||
| fs.writeFile( | ||
| altimatePath, | ||
| JSON.stringify({ | ||
| altimateUrl: "https://api.test", | ||
| altimateInstanceName: "tenant", | ||
| altimateApiKey: "gateway-test-key", | ||
| }), | ||
| { mode: 0o600 }, | ||
| ) | ||
| const altimateFileExists = () => | ||
| fs.stat(altimatePath).then( | ||
| () => true, | ||
| () => false, | ||
| ) | ||
|
|
||
| yield* Effect.promise(() => fs.mkdir(dataDir, { recursive: true })) | ||
| yield* Effect.promise(() => fs.mkdir(path.dirname(altimatePath), { recursive: true })) | ||
| yield* Effect.promise(() => writeAltimate()) | ||
| yield* Effect.promise(() => | ||
| fs.writeFile( | ||
| authPath, | ||
| JSON.stringify({ anthropic, "altimate-backend": { type: "api", key: "gateway-test-key" } }), | ||
| { mode: 0o600 }, | ||
| ), | ||
| ) | ||
|
|
||
| const logout = yield* opencode.spawn(["providers", "logout", "altimate-backend"], { | ||
| env: { OPENCODE_AUTH_CONTENT: "" }, | ||
| }) | ||
| opencode.expectExit(logout, 0, "providers logout altimate-backend") | ||
| expect(logout.stdout).toContain("Logout successful") | ||
| expect(yield* Effect.promise(() => altimateFileExists())).toBe(false) | ||
| expect(JSON.parse(yield* Effect.promise(() => fs.readFile(authPath, "utf8")))).toEqual({ anthropic }) | ||
|
|
||
| // Credentials saved only to altimate.json (TUI paste dialog) must still be removable. | ||
| yield* Effect.promise(() => writeAltimate()) | ||
| const fileOnlyLogout = yield* opencode.spawn(["providers", "logout", "altimate-backend"], { | ||
| env: { OPENCODE_AUTH_CONTENT: "" }, | ||
| }) | ||
| opencode.expectExit(fileOnlyLogout, 0, "providers logout file-only altimate-backend") | ||
| expect(fileOnlyLogout.stdout).toContain("Logout successful") | ||
| expect(yield* Effect.promise(() => altimateFileExists())).toBe(false) | ||
| expect(JSON.parse(yield* Effect.promise(() => fs.readFile(authPath, "utf8")))).toEqual({ anthropic }) | ||
| }), | ||
| 120_000, | ||
| ) | ||
| }) | ||
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.
Minor (not a blocker, safe to do in a follow-up): "requests stop" overstates the result for running processes
CLI logout doesn't reach an already-running
serve/TUI process. Its provider state keeps the loaded key in memory until it is restarted or disposed. Suggested wording: "new sessions stop authenticating; restart running sessions or use/logoutinside them." Combined with the MCP entries flagged onproviders.ts:650, this sentence is currently not fully accurate.