You have two choices.
- Add the user info in the token response by adding the extra claims, see can I include user information while issuing an access token?
- Implement an userinfo endpoint
Such as
@RestController
@ProcessingController
@RequestMapping("/identity/userinfo")
public class UserInfoController {
@RequestMapping(value = "", method = RequestMethod.GET)
public ResponseEntity<?> userInfo(Principal principal,
HttpServletRequest request) {
return ResponseEntity.ok(principal);
}
}
And make sure you have a resourceServer that is configured to use oauth2 at that endpoint
@Configuration
public class ResourceServerConfig {
@Autowired
private ResourceServerTokenServices defaultTokenServices;
@Bean
protected ResourceServerConfiguration identityResources() {
ResourceServerConfiguration resource = new ResourceServerConfiguration() {
// Switch off the Spring Boot @Autowired configurers
public void setConfigurers(List<ResourceServerConfigurer> configurers) {
super.setConfigurers(configurers);
}
};
resource.setConfigurers(Arrays.asList(new ResourceServerConfigurerAdapter() {
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.resourceId(ResourceId.IDENTITY_API.getName())
.tokenServices(defaultTokenServices);
}
@Override
public void configure(HttpSecurity http) throws Exception {
http
.requestMatchers()
.antMatchers("/identity/**")
.and()
.authorizeRequests()
.antMatchers("/identity/userinfo/**").hasAnyAuthority("ROLE_USER_INFO")
.anyRequest().authenticated();
}
}));
resource.setOrder(3);
return resource;
}
}