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
Refresh Keycloak tokens during long-running CaPyCLI SW360 operations #241
CaPyCLI obtains a Keycloak OAuth2 access token once when a command starts and uses it for the remainder of the command execution.
Some individual CaPyCLI commands can perform large numbers of online SW360 requests and run longer than the current 10-hour access-token lifetime. Later requests may therefore use an expired token and fail.
A concrete expired-token error message is not yet available. This issue is based on an observed command duration exceeding the configured token lifetime.
Goal
Provide a general, centralized solution for renewing Keycloak client-credentials tokens during long-running CaPyCLI commands that access SW360.
The solution should apply only when CaPyCLI has client credentials and can obtain a replacement token. A caller-supplied bearer token cannot be refreshed by CaPyCLI.
Initial implementation plan
Introduce a centralized token lifecycle abstraction for client-credentials authentication that retains the client ID, client secret, access mode, and token expiry.
Refresh the token shortly before expiry and transparently update or safely recreate the active SW360 client/session.
On 401 Unauthorized, refresh the token once and retry the failed request once, without retrying unrelated failures.
Preserve the existing behavior for caller-supplied bearer tokens.
Ensure write operations cannot unintentionally repeat a completed non-idempotent request.
Add automated tests for proactive renewal, 401 renewal and retry, refresh failures, read/write behavior, and non-disclosure of sensitive values.
Document the behavior and known limitations.
Acceptance Criteria
Long-running CaPyCLI commands using -client_id and -client_secret continue to access SW360 after the original token expires.
Token refresh is implemented in a shared layer rather than separately in individual commands.
CaPyCLI refreshes the token shortly before expiry when expiry information is available.
A 401 Unauthorized response causes at most one token refresh and retry of the failed request.
Caller-provided bearer tokens continue to work unchanged and are not treated as refreshable.
Write operations are not retried where doing so could duplicate a completed non-idempotent operation.
Client secrets and bearer tokens are not written to logs, exceptions, or diagnostic output.
Automated tests cover the token lifecycle and retry behavior.
Note that the code for the keycloak token management is rather fresh and in general might need some cleanups (better error handling, code deduplication). In #240, I at least tried to slightly improve the documentation for this new feature, but this is still a draft yet.
So in a nutshell, we probably should align on a concrete plan before jumping into any implementation. So did you already have a closer look on the code base and have some concrete suggestions besides the high-level (AI?) implementation plan you suggest above?
Hi @gernot-h, we saw the PR related to this issue - thank you for the quick action! We've inspected it and it seems like it addresses our concerns and will solve any issues that can be faced in the future. Is there a planned date for the merge of that PR?
Hi @gernot-h, we saw the PR related to this issue - thank you for the quick action! We've inspected it and it seems like it addresses our concerns and will solve any issues that can be faced in the future. Is there a planned date for the merge of that PR?
Activity
gernot-h commentedon Sep 9, 2026
Thank you for the report, @AlaraPiskin!
Note that the code for the keycloak token management is rather fresh and in general might need some cleanups (better error handling, code deduplication). In #240, I at least tried to slightly improve the documentation for this new feature, but this is still a draft yet.
So in a nutshell, we probably should align on a concrete plan before jumping into any implementation. So did you already have a closer look on the code base and have some concrete suggestions besides the high-level (AI?) implementation plan you suggest above?
AlaraPiskin commentedon Sep 17, 2026
Hi @gernot-h, we saw the PR related to this issue - thank you for the quick action! We've inspected it and it seems like it addresses our concerns and will solve any issues that can be faced in the future. Is there a planned date for the merge of that PR?
gernot-h commentedon Sep 23, 2026
Sorry for the delay, I'll try to review it asap!