You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
token refresh saves tokens under the context name instead of the user name #536
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 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).
logout and context --delete only clean the referenced user, so the orphan entry with the newest tokens stays on disk.
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.
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 ran microcks 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:
users:
- name: http://127.0.0.1:18736 # the user the context points torefresh-token: OLD-REFRESH # unchanged
- name: dev-context # new entry nothing resolvesrefresh-token: NEW-REFRESH
refreshAuthToken calls UpsertUser with ctxName, but users are keyed by server URL. It should upsert using configCtx.User.Name.
Confirmed again on current master (git log -1: after the latest merges): refreshAuthToken in pkg/connectors/microcks_client.go (~line 381) still calls UpsertUser(config.User{Name: ctxName, ...}), while login keys the user by server URL and the context points to it via User. This matches the reproduction posted on Oct 14, with the new tokens written to an orphan dev-context user 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 that users still 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.
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.
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