Skip to content
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

CORS errors #400

Closed
dmead opened this issue Feb 19, 2018 · 15 comments
Closed

CORS errors #400

dmead opened this issue Feb 19, 2018 · 15 comments
Assignees
Milestone

Comments

@dmead
Copy link

dmead commented Feb 19, 2018

Hi guys

I've got the plugin installed and can authenticate when i start chrome with no security (google-chrome --disable-web-security --user-data-dir)

However, when I run the plugin as normal it errors out when i use either password or passwordless logins.

In the chrome console i see:

Failed to load https://<my-domain>.auth0.com/passwordless/verify: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://<my-domain>.com' is therefore not allowed access.

Should I be editing my apache config to fix this? or does wordpress prefer I do something else?

@joshcanhelp joshcanhelp self-assigned this Feb 19, 2018
@dmead
Copy link
Author

dmead commented Feb 20, 2018 via email

@dmead
Copy link
Author

dmead commented Feb 20, 2018

I've done a fresh install of the latest wordpress with the latest auth0 plugin.

Still the same error. Even doing stuff like below in apache doesn't help. Gets fail on cross site policy and posts fail pre-flight checks.

Header set Access-Control-Allow-Origin "*"

auth0

Any ideas? Should this need cors adjustments at all?

@joshcanhelp
Copy link
Contributor

@dmead - Apologies for the delay here.

The CORS error is coming from the Auth0 server, it's saying that your domain is not allowed to access the Auth0 server. This is to be expected for everything except your domain, once it's been added. Just so we're on the same page, make sure that:

  • Your Client settings > "Allowed Callback URLs" have the right URLs added, similar to the screenshot below (but with your domain, of course); the "Allowed Origins (CORS)" setting will pull from these:

screenshot 2018-02-20 11 08 53

  • Make sure your Twilio account is setup properly, the SMS connection is active in your dashboard, and your client is authorized on there.

All that said, I'm also seeing this error on my local install ("headless" WP setup similar to this, nothing out of the ordinary) so I'll need to investigate a bit to see why this is happening. It's possible that it's a configuration issue that can be corrected easily but I need to hunt down what's missing.

One thing to note ... the newest version of Lock (the JavaScript that powers the login form) has passwordless built in so an upgrade to the plugin to account for that will be coming soon. I'll fast-track testing that and see if I can get a patch your way if the configuration doesn't pan out.

@dmead
Copy link
Author

dmead commented Feb 20, 2018

We have all that setup and the CORS headers configured in apache.

Twilio works because i can get an authorization code, but on submit it fails CORS policy like a POST should (pre flight blah blah).

And like I said, the entire process works if i just disable cors on the browser, so it's not the configuration.

I've even tried patching the plugin so it serves the javascript from my apache instance (no auth0 cdn involved) and it still errors out. If you'd like more specific debug info i'd be happy to provide privately.

@dmead
Copy link
Author

dmead commented Feb 20, 2018

I've tried your suggest changes and had the same result

@joshcanhelp
Copy link
Contributor

Again, your Apache configuration doesn't need to change as this is a call from your browser to Auth0, won't make a difference either way. Also, where the JS loaded won't matter for this either (though there is a field in the plugin that allows you to change that).

For the "disable cors on the browser," I'm sorry I mis-read that originally, I thought you said it didn't work that way. I think you're probably affected by this:

https://auth0.com/docs/cross-origin-authentication

I'll do some testing today or Monday and see if I can't help you get this figured out.

@alerdenisov
Copy link

@joshcanhelp did you some tests already?
Because same problem in my case

@joshcanhelp
Copy link
Contributor

Apologies for the delayed response here.

I'm seeing the same issue you're having @dmead and have been digging into a fix over the last week. I think the problem stems from newer tenants not having access to older API endpoints. The library that runs passwordless in this plugin is out-of-date and has since been merged with the main library that runs that login page, Lock.

All that to say: this needs some work on our end and it's high priority to get that working. It will need some thorough testing but we'll make sure it's in the next release. I might be able to package it up into a plugin to try out before it and, if I'm able, I'll post instructions here.

Thanks for your patience!

@joshcanhelp joshcanhelp added this to the v3-Next milestone Mar 24, 2018
@joshcanhelp
Copy link
Contributor

joshcanhelp commented Apr 2, 2018

Edit: removed the testing plugin link. Please use the dev branch of this repo to test this new behavior in a non-production environment.

@zackdn
Copy link

zackdn commented Apr 6, 2018

@joshcanhelp I was having the same issue on a WPengine staging environment and applied your fix. Works like a charm!

I did still get an error on the initial load of the page, but login worked regardless:

Failed to load https://xxxx.auth0.com/user/geoloc/country: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

@joshcanhelp
Copy link
Contributor

Good to hear!

That error won't affect logging in, it's just trying to get the country to auto-fill values. Check your CORs setting in the dashboard to make sure you've got everything configured.

@dmead @alerdenisov - Are you able to test this out to see if it solves your issue?

@joshcanhelp
Copy link
Contributor

Fixed in #434 and merged into dev. Please deactivate and delete the test plugin linked here before upgrading!

@leobarcellos
Copy link

Hi @joshcanhelp, I know this was closed and probably my comment is kinda offtopic because I'm not using wp-auth0. However I'm using auth0.js SDK and facing the same problem. Passwordless and CORS issues.

I've configured Allowed Callback URLs already, and I'm using a custom domain. However even with the .auth0.com I get the CORS Issue with the passwordless.verifyCode function.

Question 1: Is it possible to add the Access-Control-Allow-Origin on my custom domain?
Question 2: Is it possible to get the auth0.min.js in my custom domain? Because I guess this issue will be resolve since calls will be in the same domain.

PS: all my calls are being requested inside the same root domain.

@joshcanhelp
Copy link
Contributor

Hi @leobarcellos ... this is a pretty specific issue with the WP plugin (more specifically, Lock) and is closed because the fix is merged into the dev branch here for anyone that wants to test it out.

The CORS errors you're seeing could be a number of different things, most commonly an incorrectly configured "Allowed Callback URLs" field, the one you mentioned. If that's definitely correct (the non-Auth0 domains you're using have been added), then the next most common is related to cross-origin authentication. It sounds like you're addressing that with a custom domain but it would be worth it to run through that doc again just in case.

If you're still having the issue, we'll need reproduction steps so we can test it on our end. Include the code you're using on the page (exclude any sensitive info like your Client ID) and the steps you're taking to see the error. If this is in WordPress and you're testing with the dev branch here then this issue thread is fine. If it's Auth0.js, then use the Issue queue there.

This was referenced May 30, 2018
@sgedda
Copy link

sgedda commented Sep 3, 2018

Also make sure that request header is not set to 'Access-Control-Allow-Origin': '*' which was the reason to the error in my case.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants