-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Response for preflight has invalid HTTP status code 401 #34
Comments
Are you running your Angular 2 client on a dev-server? Like is it running on a different port(4200) |
Yes i do |
Sounds to me like the request header from Angular 2 is wrong. Have you set
|
Still the same problem Here is my code Spring Cors Filter: public class SimpleCORSFilter implements Filter {
} Angular code sendCredential(model) {
} sendToken(token) {
} Login component onSubmit() {
} |
@igoravramovic
|
@bfwg You're right, I didn't include the "Bearer" prefix, yet. But I've opened a ticket for that. |
@igoravramovic could you fix your problem? |
Sorry for not responding more quickly, i was not able to take time to try proposed solution |
I was having the same issue with the prefight OPTIONS request return a 401. When the OPTIONS request is sent from angular 2, it's sent without the Authorization header. Spring Security tries to authenticate the request without the header and returns a 401. In the I added a filter before the
In my security config I added the bean for the filter and added it to the configuration before
This seems to be working for me. Hope this helps you. |
@igoravramovic is this helping you? |
@jmw5598 - I'm not sure if this can help, but try putting @Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(HttpMethod.OPTIONS, "/**");
} On your |
@jrcastillo you are absolutely right, and this should solve OP's problem except he has to remove the Bearer part. To understand the original problem, please follow this link https://stackoverflow.com/questions/38368794/angular-2-basic-authentication-not-working |
@igoravramovic is not replying since 19th Apr so I close this ticket now. |
You can get through this very easy! Let's follow me right now
So the reason that we get multiple errors when working with woo-commerce-api is this "web-security" by Google. Then you just disable it and you actually don't need any CORS Extensions. So remove them right now if you have installed. And this solution i write for people who learn this course https://www.udemy.com/ionic-3-apps-for-woocommerce-build-an-ecommerce-mobile-app/. This is an ionic e-commerce app that using woo-commerce-api to set and get data from Wordpress (local or live server). If you have trouble in other language not ionic, it still works fine. Actually i have done a lot of searchings on Google to find this solution. I hope this helps all of you. Now, i need to go to bed because tomorrow i have a final report about this ionic project with my lecturer 😃 See ya! |
@jrcastillo thanks for the tip And if anyone is using HttpSecurity then we need to use this
|
I can not for the life of me get cors to work on this project. I tried all of the above & nothing works. The only change I've been able to get working is applying a filter which only works after the user is already logged in showing the new headers on the response, but still fails a preflight request.
|
update after trying a ton of things the solution for me ended up being the following:
and adding
at the top of each controller |
I have created angular 2 client
But i receive this error when i call /user method
Response for preflight has invalid HTTP status code 401
The text was updated successfully, but these errors were encountered: