Fix OIDC token refresh to handle missing refresh_token in response#384
Open
DarshanCode2005 wants to merge 2 commits intotomplus:mainfrom
Open
Fix OIDC token refresh to handle missing refresh_token in response#384DarshanCode2005 wants to merge 2 commits intotomplus:mainfrom
DarshanCode2005 wants to merge 2 commits intotomplus:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: #296
Problem
The
_refresh_oidcmethod inkube_config.pyassumes that arefresh_tokenwill always be returned in OAuth2 token refresh responses. However, different token management strategies may not return a refresh token in every refresh response:This causes a
KeyError: 'refresh_token'at line 335 when the refresh response doesn't include a new refresh token.Solution
Modified
_refresh_oidcto conditionally update the refresh token only if it's present in the response:if "refresh_token" in resp:
provider["config"].value["refresh-token"] = resp["refresh_token"]. This preserves the existing refresh token when a new one isn't provided, which is the correct behavior for sliding token strategies.
Changes
_refresh_oidcmethod to check forrefresh_tokenbefore updatingtest_oidc_with_refresh_no_new_refresh_tokento verify behavior when refresh_token is not returnedTesting