Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --force-refresh flag to get-token to refresh ID token #879

Merged
merged 1 commit into from
Feb 17, 2023

Conversation

linki
Copy link
Contributor

@linki linki commented Feb 10, 2023

This PR adds a flag to get-token called --force-refresh which always renews the ID token regardless of its expiration time.

When kubelogin finds an existing CachedTokenSet it expects to have both an IDToken and a RefreshToken. It would then check the IDToken's expiration time and might skip a refresh if it's still valid.

By using --force-refresh the check for the IDToken's expiration time will always be skipped. This will trigger kubelogin's normal token renewal procedure, either automatically (if a refresh token is present) or via the browser (if there's no cached token in the first place).

We have a use case where we prematurely want to refresh the ID token before its regular expiration time because we know the newly requested token will have additional properties that we want. Instructing kubelogin get-token to forcefully refresh the token on a case-by-case basis would help us a lot: Previously we would remove the cached token file on the file system completely, but that would also remove the refresh token and requires a dreadful login via the browser (at least it pops up for a moment). By keeping the cached token file (with the refresh token) in place and using --force-refresh instead, the process is seamless for the person using the client.

This PR misses tests but functionality has been tested manually. If the approach taken here seems reasonable to be merged I would also work on appropriate tests.

This should also fix #659 /cc @Xartos

@int128 int128 self-requested a review February 10, 2023 23:46
Copy link
Owner

@int128 int128 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

@int128 int128 merged commit f03d4fe into int128:master Feb 17, 2023
@linki linki deleted the force-refresh branch February 17, 2023 11:10
@linki
Copy link
Contributor Author

linki commented Feb 22, 2023

@int128 Thanks for merging this!

Would you mind cutting a new release with it (probably v1.27.0) so that there are pre-built binaries that can be downloaded?

@int128
Copy link
Owner

int128 commented Mar 1, 2023

I will soon create a new release.

@int128
Copy link
Owner

int128 commented Mar 1, 2023

@linki
Copy link
Contributor Author

linki commented Mar 2, 2023

@int128 Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Force refresh token
2 participants