token refresh saves tokens under the context name instead of the user name
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- go
- Domain
- authentication, cli
Research direction
Start in pkg/connectors/microcks_client.go at refreshAuthToken and inspect how configCtx resolves the referenced user. Review the refresh test from #487, then add coverage where the context name differs from contexts[].user. Done means refreshed tokens update the referenced server-named user without creating an orphan entry.
Written by the indexing model from the issue text.
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-TOKEN
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).
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.
- Dominant language
- Go
- Stars
- 52
- Forks
- 67
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 13
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microcks/microcks-cli
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
microcks/microcks-cli#535 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
microcks/microcks-cli#534 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
microcks/microcks-cli#511 ·
-
component/cli kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
microcks/microcks-cli#503 · 4 comments ·
-
stale
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
microcks/microcks-cli#483 · 3 comments ·
All issues in microcks/microcks-cli
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
kind/cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
kubernetes-sigs/kueue#15947 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sympozium-ai/sympozium#627 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100