Facebook requires a website URL
, where the website is hosted for validating Oauth requests. Facebook also requires valid callback URLs
, basically a list of URLs that Facebook can securely pass Oauth tokens to.
Here's the difference in my local environment versus my cloud9 environment, concerning Facebook Oauth setup:
Localhost:
http://localhost:3000
http://localhost:3000/auth/facebook/callback
Cloud9:
http://myapp-cireficc.c9.io/
http://myapp-cireficc.c9.io/auth/facebook/callback
My localhost setup works just fine. However, when I run my app on cloud9, I get the following error from Facebook:
Given URL is not allowed by the Application configuration: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.
This is implying that one of these two parameters are wrong... and after a bit of debugging, it looks like Facebook is trying to access this callback URL:
redirect_uri=http%3A%2F%2Fmyapp-cireficc.c9.io%3A80%2Fauth%2Ffacebook%2Fcallback
And after decoding that into more readable characters, we have:
http://myapp-cireficc.c9.io:80/auth/facebook/callback
It seems like this random :80 is being added to the callback URL, which makes me think that when the Oauth request gets sent out, it's being appended, and Facebook is just dutifully attaching it to the response callback, which is now incorrect. Because the :80 is being added, the expected and actual callbacks differ:
expected: http://myapp-cireficc.c9.io/auth/facebook/callback
actual: http://myapp-cireficc.c9.io:80/auth/facebook/callback
This seems to me to be something cloud9 is adding when it sends out the request (maybe due to how their domain names are set up?). What can I do to get Facebook Oauth working on cloud9?
Note: Cloud9's env.PORT
is 8080
, and env.IP
is 0.0.0.0
. This seems to be where the :80 in the callback is coming from, but I have no idea how to get around the issue.
Interestingly enough, I have my staging environment set up on Heroku, and Heroku doesn't have this issue. I can easily access Facebook Oauth there by using http://myapp-staging.herokuapp.com
and the correct callback URL.
Had the same issue: adding the port (:80) to the cloud9 url, then adding it to the Valid OAuth redirect URIs fixed it for me.
@AnthonyGrove's answer did not work for me.
However, adding the port (:8080) to the cloud9 url, then adding it to the Valid OAuth redirect URIs fixed it for me.
From the docs: Please note that 8080, 8081, and 8082 are the only available ports on a hosted Cloud9 workspace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With