'OAuth2AuthorizedClient is always null @ azure implementation
I am currently try to get the refreshtoken because at a certain time the token will be unvalid and I would like to refresh my accesstoken.
Problem is that OAuth2AuthorizedClient is always Null.
@Autowired
private OAuth2AuthorizedClientService authorizedClientService;
public CurrentUser getCurrentUser() {
final SecurityContext securityContext = SecurityContextHolder.getContext();
final Authentication auth = securityContext.getAuthentication();
if (auth != null) {
if (auth instanceof OAuth2AuthenticationToken) {
OAuth2AuthenticationToken authToken = (OAuth2AuthenticationToken) securityContext.getAuthentication();
OAuth2AuthorizedClient client = authorizedClientService
.loadAuthorizedClient(authToken.getAuthorizedClientRegistrationId(), authToken.getName());
final DefaultOidcUser userPrinciple = (DefaultOidcUser) auth.getPrincipal();
OAuth2RefreshToken refreshToken = client.getRefreshToken();
return (CurrentUser) userPrinciple;
} else if (auth instanceof JwtAuthenticationToken) {
return createCurrentUserFromAuth((JwtAuthenticationToken) auth);
}
}
return null;
}
IdentityProvider: Azure
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|