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-token to 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).
logout and context --delete only 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.
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, butusersentries are keyed by the server URL. So it appends a new entry instead of updating the one the context points to.loginkeys the user by server URL:refreshAuthTokenwrites it back withctxName: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-contextauth-tokento an expired JWT)cat ~/.config/microcks/configLogin without
--nameis fine, there the context name and user name are both the server URL.Actual behavior
logoutandcontext --deleteonly clean the referenced user, so the orphan entry with the newest tokens stays on disk.Suggested fix
configCtxis already resolved a few lines above:The refresh test in #487 uses a config where
contexts[].userequals the context name, so it passes with this bug. A regression test needs the two to differ.