-
Notifications
You must be signed in to change notification settings - Fork 6k
OAuth2 client doesn't update token when refresh of token had failed #10016
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
Comments
The refresh token is removed when the
then the test passes. Or, if I change your configuration to do: clientManager.setAuthorizationFailureHandler(
new RemoveAuthorizedClientOAuth2AuthorizationFailureHandler(
(clientRegistrationId, principal, attributes) -> clientService
.removeAuthorizedClient(clientRegistrationId, principal.getName()),
Collections.singleton("test")
)
); then the test also passes. Or, if you need something more flexible than that, you can wire your own clientManager.setAuthorizationFailureHandler((exception, principal, attributes) -> {
String registrationId = ((ClientAuthorizationException) exception).getClientRegistrationId();
clientService.removeAuthorizedClient(registrationId, principal.getName());
}); then the test also passes. I'm going to close this as answered, but please comment if you feel like there's more to discuss. |
Thank you for your quick answer! We're getting But this will require upgrading from Spring Boot 2.2.8.RELEASE (Spring Security 5.2.5.RELEASE) to newer version. And latest Spring Security versions doesn't seem to be compatible with Spring Boot 2.2.8. So, I'm wondering, is there any chance, that we can use this behavior without upgrading Spring Boot now? Also, I've created Thank you! |
The functionality is available in Security 5.3/Boot 2.3 - are you able to at least update to that? Note that Spring Boot 2.2 is scheduled to reach End-of-Life in July 2021. Otherwise, I imagine that you could create a delegate implementation of OAuth2AuthorizedClientManager wrapperManager = (request) -> {
try {
return clientManager.authorize(request);
} catch (ClientAuthorizationException ex) {
String registrationId = ex.getClientRegistrationId();
String name = request.getPrincipal().getName();
clientService.removeAuthorizedClient(registrationId, name);
}
}; |
Thanks for the help! We will schedule an update of our applications and use this approach until it's done. |
Describe the bug
We're using Spring security OAuth2 client with grant type
password
. It uses bothaccess_token
andrefresh_token
. Whenaccess_token
expires, token tries to refresh and we're getting error from backend.In this case, token is not refreshed and not removed from token repository and next call to API, tries to refresh token with same (wrong) refresh token, thus causing infinite loop for token refresh.
To Reproduce
Please, see attached sample.
Expected behavior
It's expected to get new
access_token
andrefresh_token
pair using grant type other thanrefresh_token
when refresh had failed.Sample
https://github.com/geobreze/oauth2-client-refresh-token-demo
The text was updated successfully, but these errors were encountered: