Spring boot rest service options 401 on oauth/token

前端 未结 4 1792
予麋鹿
予麋鹿 2020-12-05 16:06

I\'m using spring boot to make a simple rest service. To consume it in Angular 2, I\'ve got CORS problem when retrieving token on oauth/token endpoint.

The error mes

4条回答
  •  情深已故
    2020-12-05 16:34

    The browser checks CORS settings via a request with OPTIONS header. And if you've configured authorization, OPTIONS request will be blocked as unauthorized.

    You simply can add cors support in WebConfigurerAdapter.

    @EnableWebSecurity
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            // ...
            http.cors();
        }
    }
    

    Check this link for more info: https://www.baeldung.com/spring-security-cors-preflight

提交回复
热议问题