In UserInfoTokenService (org.springframework.boot.autoconfigure.security.oauth2.resource)
private OAuth2Authentication extractAuthentication(Map<String, Object> map) {
...
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
principal, "N/A", authorities);
token.setDetails(map);
return new OAuth2Authentication(request, token);
org.springframework.security.oauth2.provide.OAuth2Authentication:
public OAuth2Authentication(OAuth2Request storedRequest, Authentication userAuthentication) {
super(userAuthentication == null ? storedRequest.getAuthorities() : userAuthentication.getAuthorities());
this.storedRequest = storedRequest;
this.userAuthentication = userAuthentication;
}
Always sends the userAuthentication , even when the token is obtained by client_crendetials grant type. This causes a fail in OAuth2Authentication
public boolean isClientOnly() {
return userAuthentication == null;
}
Since the userAuthentication will never be null.