I am using JWT in my Spring Boot app. When I try to login from the Angular 6 client, I get the CORS error
Access to XMLHttpRequest at \'http://localhost:8082
Since message is about your preflight request i.e. OPTIONS
request,
I guess, you need to do two things on server side / Spring Boot code ,
attemptAuthentication
method as first check i.e. don't do real authentication for preflight requests, if (CorsUtils.isPreFlightRequest(httpServletRequest)) {
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
return new Authentication() ; //whatever your token implementation class is - return an instance of it
}
CorsUtils is - org.springframework.web.cors.CorsUtils
.authorizeRequests().antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
You can allow unauthorized OPTIONS requests too but I guess , that wouldn't be a good idea. Also, try to narrow down "/**" to specific URLs if possible.