Announcement Announcement Module
No announcement yet.
auth.getAuthorizationRequest().getClientId() is null Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • auth.getAuthorizationRequest().getClientId() is null

    Below statement is giving me null. please help me what i am missing


    auth is OAuth2Authentication

  • #2
    Where did you get the OAuth2Authentication from? It depends entirely on who actually created it, whether or not the client id is there.


    • #3
      From my controller.. Here is sample code

      @RequestMapping(value = "/{" + CUSTOMER_ID + "}", method = RequestMethod.GET)
      @PreAuthorize("#oauth2.clientHasRole('ROLE_CLIENT' )")
      public Customer getCustomer(@PathVariable(CUSTOMER_ID) String customerId, OAuth2Authentication auth) {

      And i am able to see the client in token store (I am using Spring InMemoryToken store)


      • #4
        If you put an object in a controller method parameter and no extra declarations to tell what Spring to do it will just create a new instance from the default constructor, so that probably explains why it is not setting the client id. What did you need it for? Is this a request that is authenticated through the OAuth2 authentication processing filter? If so then the Spring Security context should have an instance of OAuth2Authentication in it (and you can get that in a controller method by asking for a Principal).