Allow OPTIONS HTTP Method for oauth/token request

前端 未结 5 1381
不思量自难忘°
不思量自难忘° 2020-12-04 19:17

I\'m trying to enable oauth2 token fetching for my angular application. My configuration is working fine (authentication is working correctly for all requests, token fetchin

5条回答
  •  时光说笑
    2020-12-04 20:12

    @EnableAuthorizationServer is adding http security configuration for endpoints like /oauth/token, /oauth/token_key etc at order 0. So what you should do is to define a http security rule for /oauth/token endpoint only for the OPTIONS http method which is at a higher order.

    Something like this:

    @Order(-1)
    @Configuration
    public class MyWebSecurity extends WebSecurityConfigurerAdapter {
       @Override
       protected void configure(HttpSecurity http) throws Exception {
           http
              .authorizeRequests()
              .antMatchers(HttpMethod.OPTIONS, "/oauth/token").permitAll()
       }
    }
    

提交回复
热议问题