Repository navigation
fix(api): derive default API base URL from the login environment - #13
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation and coverage are sound; the remaining README wording issue is non-blocking.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Derives the default lfx api base URL from the authenticated environment rather than persisted audience data.
Changes:
- Validates stored audiences against compiled-in environment defaults.
- Documents the updated audience and API routing behavior.
- Adds unit and integration coverage for mismatched audiences.
| File | Description |
|---|---|
README.md |
Documents default API routing behavior. |
internal/commands/api.go |
Adds environment-based URL selection and validation. |
internal/commands/api_test.go |
Tests defaults and mismatch refusal. |
internal/commands/auth.go |
Updates token-resolution documentation. |
internal/credstore/credstore.go |
Clarifies persisted audience usage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Without --hostname, `lfx api` now always uses the compiled-in default API audience for the login's environment as its base URL, rather than the audience value persisted in state.json. A stored audience that differs from that default is refused with an error asking the user to run `lfx auth login` again (or, for development logins, to pass --hostname explicitly), mirroring the existing IdP domain consistency check in loadDeviceStateForBackend. Logins made with a non-default --audience therefore need --hostname (development only) to use `lfx api`; `lfx auth token` is unaffected. Signed-off-by: David Deal <ddeal@linuxfoundation.org> Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L8qMuq3je1uuU2JMLHuYBG
2d50739 to
cbe5782
Compare
Describe the environment's default API as the behavior when --hostname is not passed, rather than implying it applies unconditionally. Signed-off-by: David Deal <ddeal@linuxfoundation.org> Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L8qMuq3je1uuU2JMLHuYBG
|
Following up on this approach: I confirmed it effectively nullifies Given that (a) this isn't documented anywhere today —
This is more defensible as a security fix than comparing a stored value against the table: there's no longer an Can push this as a revision to this PR if that works, rather than opening a new one. |
|
Correction on my last comment: the doc gap isn't the README (which doesn't cover either flag), it's the in-CLI help. Doesn't change the recommendation: removing |
|
Thanks @emsearcy, agreed: removing Generated by Claude Code |
…uubawi Resolve the README conflict by keeping both the device login URL note from main and the lfx api default base URL note from this branch. Signed-off-by: David Deal <ddeal@linuxfoundation.org> Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L8qMuq3je1uuU2JMLHuYBG
|
@dealako thanks—I see your merge commit, but not the commit removing |
…only Per review feedback on this PR: the prior approach (validating a persisted `--audience` against the environment's compiled-in default) left `--audience` effectively dead outside `development`, since `lfx api` could never use a non-default stored audience and `--hostname` was independently gated to development logins. Instead of validating, remove the ability to configure either value at all: - `lfx auth login` no longer accepts `--audience`; the audience sent to Auth0's device code endpoint is always the compiled-in default for `--env` (defaultAudienceForEnvironment). - `lfx api` no longer accepts `--hostname`; its base URL is always the compiled-in default audience for the login's environment. - `credstore.DeviceState` no longer persists `Audience`; nothing in state.json can influence which host receives a bearer token anymore. - `lfx auth status`'s "Audience:" line is now computed from the stored Environment via defaultAudienceForEnvironment, not read back from state.json. - Removed `apiDefaultBaseURL` and its now-obsolete tests (the audience-mismatch validation and tampered-audience end-to-end test), since there's nothing left to validate against. Suggested release: minor (removes two user-facing flags). Signed-off-by: David Deal <ddeal@linuxfoundation.org>
|
Pushed |

Summary
lfx auth login --audienceandlfx api --hostnameare removed. Neither the audience requested at login nor the API base URLlfx apiuses is configurable per invocation anymore; both are always the compiled-in default for the login's--env(seelfx auth environments).This replaces the PR's original approach (persisting the login audience and validating it against the environment's compiled-in default before using it as
lfx api's base URL), per review feedback: that approach left--audienceeffectively dead outsidedevelopment, since a non-default stored audience could never actually be used bylfx api, and--hostnamewas independently gated to development logins. Removing both flags (and no longer persisting an audience at all) is a cleaner fix: there's no longer anaudiencefield instate.jsonto tamper with, and no--hostnameescape hatch to reason about.Changes
internal/commands/auth.go: removes--audiencefromlfx auth login; the audience sent to Auth0's device code endpoint is alwaysdefaultAudienceForEnvironment(env).lfx auth status's "Audience:" line is now computed from the storedEnvironmentthe same way, instead of read back fromstate.json.internal/commands/api.go: removes--hostnamefromlfx api; its base URL is unconditionallydefaultAudienceForEnvironment(env). Removes the now-unreachableapiDefaultBaseURLvalidation helper.internal/commands/environment.go: doc-comment updates for the above (drops the--hostname/--audiencerationale that no longer applies).internal/credstore/credstore.go: removesDeviceState.Audience-- nothing instate.jsoncan influence which host receives a bearer token anymore.internal/commands/api_test.go: removesTestAPIDefaultBaseURLandTestRunAPIRefusesTamperedAudience(both tested the removed validation layer; there's nothing left to validate against).internal/credstore/credstore_test.go: dropsAudiencefrom theDeviceStateround-trip test.README.md: updates thelfx apibase URL description to reflect that it's no longer configurable.Behavior changes
lfx auth login --audienceandlfx api --hostnameno longer exist; passing either is a parse error.lfx auth login's requested audience, andlfx api's base URL, are always the compiled-in default for the login's environment -- there is no supported way to point either at a different API/audience anymore, including indevelopment.audience) keep working:Audienceis simply ignored/dropped fromstate.jsonon the next write, since it's no longer part ofDeviceState.Suggested release: minor (removes two user-facing flags).
Testing
go build ./...,go vet ./...,go test ./..., andgofmt -l .all pass.lfx auth login --helpandlfx api --helpno longer list--audience/--hostname;lfx auth login --insecure-storage --with-token --env developmentfollowed bylfx auth status --insecure-storageshows the correct compiled-inAudience:for the storedEnvironment;lfx apiagainst a stored login with an invalid refresh token fails with the expected refresh error before ever constructing a request to the API host.golangci-lint/revivewere not run locally due to an unrelated local Go-toolchain/linter export-data version mismatch (go1.27.2 vs. the installed golangci-lint's go1.27.1 build); not specific to this change.🤖 Generated with Claude Code
https://claude.ai/code/session_01L8qMuq3je1uuU2JMLHuYBG
Generated by Claude Code