-
Notifications
You must be signed in to change notification settings - Fork 6k
Ensure ID Token is updated after refresh token #16589
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
Conversation
Hi @sjohnr, Could you please review this PR? I encountered this issue during development and took the opportunity to resolve it. Thanks in advance for your time and feedback! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @yhao3. I have performed an initial review and noted a few issues below for you to consider.
.../security/oauth2/client/oidc/authentication/OidcAuthorizationCodeAuthenticationProvider.java
Outdated
Show resolved
Hide resolved
...rg/springframework/security/oauth2/client/oidc/authentication/RefreshOidcIdTokenHandler.java
Outdated
Show resolved
Hide resolved
...rg/springframework/security/oauth2/client/oidc/authentication/RefreshOidcIdTokenHandler.java
Outdated
Show resolved
Hide resolved
...rg/springframework/security/oauth2/client/oidc/authentication/RefreshOidcIdTokenHandler.java
Outdated
Show resolved
Hide resolved
Hi @sjohnr, Thanks for your review and suggestions! I’ve updated the implementation based on your feedback. |
Thanks @yhao3! I'll take another look at this hopefully early next week. |
Hi @sjohnr, Thanks for your response! I’ve made some additional adjustments to |
Hi @yhao3, thanks for your updates. Sorry for the delay, it took longer than I expected to work through the updates I felt were needed to get closer to merging this. I will post an update on the original issue for folks to give feedback. |
Hi @sjohnr, Thanks for the update! No worries at all, I really appreciate the time and effort you’re putting into this. I’ll keep an eye on the original issue for further feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a good solution to solve #15509. I've only added one comment, not sure if it is relevant or not in this scenario
...k/security/oauth2/client/oidc/authentication/OidcAuthorizedClientRefreshedEventListener.java
Show resolved
Hide resolved
* @see OAuth2AuthorizedClientRefreshedEvent | ||
* @see OidcUserRefreshedEvent | ||
*/ | ||
public final class OidcAuthorizedClientRefreshedEventListener |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it listens for OAuth2AuthorizedClientRefreshedEvent
shouldn't this listener be an OAuth2AuthorizedClientRefreshedEventListener
?
/** | ||
* An {@link ApplicationListener} that listens for events of type | ||
* {@link OAuth2AuthorizedClientRefreshedEvent} and publishes an event of type | ||
* {@link OidcUserRefreshedEvent} in order to refresh an {@link OidcUser}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the listener publish OAuth2UserRefreshedEvent
if the principal is an OAuth2User
but not an OidcUser
?
} | ||
|
||
// The current principal must be an OidcUser | ||
if (!(authenticationToken.getPrincipal() instanceof OidcUser existingOidcUser)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing for OAuth2User
would allow to process OAuth2 refresh token flows without OIDC
|
||
private static final String INVALID_NONCE_ERROR_CODE = "invalid_nonce"; | ||
|
||
private OAuth2UserService<OidcUserRequest, OidcUser> userService = new OidcUserService(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typing with OidcUserRequest
and OidcUser
might be too narrow: the OAuth2User
should be refreshed even if the provider is not configured with OIDC (calling the userinfo endpoint instead of parsing the ID token again)
Related issue: gh-15509