springspring-mvcspring-securityoauth-2.0oauth-provider

Spring OAuth (OAuth2): How can I get the client credentials in a Spring MVC controller?


In this snippet:

@RequestMapping(method = GET)
public List<Place> read(Principal principal) {
  principal.getName(); 
}

principal.getName() gives me the user identification but I need a way to receive the client credentials (client => the app who is using my API). How can I do this?


Solution

  • I found a reasonable solution based on @luke-taylor answer.

    @RequestMapping(method = GET)
    public List<Place> read(OAuth2Authentication auth) {
      auth.getOAuth2Request().getClientId()
    }