Spring security OAuth2 accept JSON

前端 未结 6 1855
深忆病人
深忆病人 2020-12-09 00:56

I am starting with Spring OAuth2. I would like to send the username and password to /oauth/token endpoint in POST body in application/json format.

curl -X PO         


        
6条回答
  •  南笙
    南笙 (楼主)
    2020-12-09 01:33

    You can modify @jakub-kopřiva solution to implement only authorization server with below code.

     @Configuration
     @Order(Integer.MIN_VALUE)
     public class AuthorizationServerSecurityConfiguration
        extends org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerSecurityConfiguration {
    
          @Autowired
          JsonToUrlEncodedAuthenticationFilter jsonFilter;
    
          @Override
          protected void configure(HttpSecurity httpSecurity) throws Exception {
                 httpSecurity
                       .addFilterBefore(jsonFilter, ChannelProcessingFilter.class);
                 super.configure(httpSecurity);
          }
    
    }
    

提交回复
热议问题