Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Oauth on Cloud9

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:

  • website URL: http://localhost:3000
  • callback URL: http://localhost:3000/auth/facebook/callback

Cloud9:

  • website URL: http://myapp-cireficc.c9.io/
  • callback URL: 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.

like image 994
Chris Cirefice Avatar asked Oct 14 '15 18:10

Chris Cirefice


2 Answers

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.

like image 181
Anthony Grove Avatar answered Oct 19 '22 19:10

Anthony Grove


@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.

like image 31
ess Avatar answered Oct 19 '22 19:10

ess