Repository navigation
Description
Describe the bug
Title: bug: token refresh saves tokens under the context name instead of the user name
Describe the bug
For contexts created with microcks login <server> --name <ctx>, the automatic token refresh saves the new tokens under the context name, but users entries are keyed by the server URL. So it appends a new entry instead of updating the one the context points to.
login keys the user by server URL:
// cmd/login.go
localConfig.UpsertUser(config.User{Name: server, ...})
localConfig.UpsertContext(config.ContextRef{Name: ctxName, Server: server, User: server})refreshAuthToken writes it back with ctxName:
// pkg/connectors/microcks_client.go:364
localCfg.UpsertUser(config.User{Name: ctxName, AuthToken: authToken, RefreshToken: refreshToken})Same context-name vs user-name mix up that was fixed in #427 for deleteContext.
How to Reproduce?
microcks login http://localhost:8080 --name dev-context- Let the access token expire (or set
auth-tokento an expired JWT) - Run any authenticated command
cat ~/.config/microcks/config
contexts:
- name: dev-context
user: http://localhost:8080 # still points here
users:
- name: http://localhost:8080
auth-token: <still expired>
refresh-token: OLD-REFRESH-TOKEN
- name: dev-context # new entry, nothing resolves it
auth-token: NEW-ACCESS-TOKEN
refresh-token: NEW-REFRESH-TOKENLogin without --name is fine, there the context name and user name are both the server URL.
Actual behavior
- The context keeps replaying the same refresh token on every command, so once it hits the Keycloak SSO idle timeout you have to log in again (and it fails right away if one time use refresh tokens are on).
logoutandcontext --deleteonly clean the referenced user, so the orphan entry with the newest tokens stays on disk.
Suggested fix
configCtx is already resolved a few lines above:
localCfg.UpsertUser(config.User{Name: configCtx.User.Name, AuthToken: authToken, RefreshToken: refreshToken})The refresh test in #487 uses a config where contexts[].user equals the context name, so it passes with this bug. A regression test needs the two to differ.
Activity
gyanranjanpanda commentedon Sep 20, 2026
could @Harsh4902 review this issue
yada commentedon Oct 14, 2026
Reproduced on master (f9550f5). I used a config with context
dev-context(user keyed by server URL), an expired access token and a refresh token, then ranmicrocks service list. The Microcks API and Keycloak endpoints were a local fake server, since the real server has Keycloak disabled. The token redeem and the config write are the real CLI code.Resulting
users:refreshAuthTokencallsUpsertUserwithctxName, but users are keyed by server URL. It should upsert usingconfigCtx.User.Name.yada commentedon Oct 28, 2026
Confirmed again on current master (
git log -1: after the latest merges):refreshAuthTokeninpkg/connectors/microcks_client.go(~line 381) still callsUpsertUser(config.User{Name: ctxName, ...}), whileloginkeys the user by server URL and the context points to it viaUser. This matches the reproduction posted on Oct 14, with the new tokens written to an orphandev-contextuser and the real user left with the expired ones.Suggested fix: write the refreshed tokens back to the user the context references, i.e.
Name: configCtx.User.Name(already loaded just above), and add a regression test with a context whose name differs from its user name, checking thatusersstill has a single entry holding the new tokens.@gyanranjanpanda, you asked about this one earlier: feel free to submit a PR (conventional-commit title, with AI usage disclosed per CONTRIBUTING.md). No one else is assigned.
Disclosure: this comment was drafted with AI assistance.
dipak0000812 commentedon Nov 10, 2026
I'll take this one up. I'll investigate the refresh flow, fix the user-reference mismatch, and add regression coverage for contexts where the context name differs from the user name.
fix: persist refreshed tokens against the context user