Facebook login only works when hosts is set to localhost? - facebook

Unfortunately I keep getting this error:
{
"error": {
"message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.",
"type": "OAuthException",
"code": 191
}
}
Login works however when my /etc/hosts file is set to: 127.0.0.1 [mysite].rhcloud.com, it only fails when I view the actual [mysite].rhcloud.com.
I am running the exact same application (on a different server) locally as the one I'm running on rhcloud. Specifically the local<->remote web-application directories are synced.
URL information
When attempting login remotely the URL looks like this; and fails with aforementioned error:
https://graph.facebook.com/oauth/authorize?scope=user_photos%2Cfriends_photos&redirect_uri=http%3A%2F%2F[mypublicipaddress]%2Fuser%2Flogin&response_type=code&client_id=[hidden]
Whereas attempting to login locally the URL looks like this; and works:
https://www.facebook.com/dialog/permissions.request?app_id=[hidden]&display=page&next=http%3A%2F%2F[hidden].rhcloud.com%2Fuser%2Flogin&response_type=code&perms=user_photos%2Cfriends_photos&fbconnect=1

OK, you seem to be doing this right, but there's one thing that sometimes trips people up, do both your redirect_uri and 'Website URL' field have a trailing '/'?
In particular, if the redirect_uri doesn't have the trailing '/' (or a filename, etc) after the domain name it doesn't always work

did you set your canvas URL/secure canvas URL in facebook app configuration. IF so, retry after removing them. Or try after making sure canvas URL should be correct.

Yes. The trailing / matters. Just check your these fields, and add that trailing / if it's not there.
But, to be honest, this is the first time I've seen something like this. Usually, we see Facebook logins failing on a local environment, but working just fine in production.

I was able to overcome exactly the same problem by accessing my facebook developer application account and changing the domain from localhost to the url of my application

Related

Error in Facebook Connect with Devise on Rails

I have spent a few hours trying to debug this issue and while there are several answers I couldn't get this to work and don't understand a few things.
I have Facebook login implemented with Devise on my Rails 3 App deployed on Heroku. I have this working fine on localhost and I had this working on production as well. I don't think I changed anything but I found out that the Facebook login was broken and can't figure out how to fix this. A few clues that may ring a bell for some -
The url I am getting where the error shows is below with the error message that many others posts show. What I find strange is the following -
Decoding the url below the redirect_uri has a port number http://www.mygreenneighbor.com:24745/auth/facebook/callback&scope=email,offline_access&
I don't think the app on Heroku is listening at this port 24745 (which btw changes when I try it after sometime) and I haven't noticed that before - is that expected?
When I make changes to my Facebook app and change the site url that change doesn't show up in the redirect uri. Does it take time for FB changes to take effect?
https://graph.facebook.com/oauth/authorize?client_id=159903734070492&redirect_uri=http%3A%2F%2Fwww.mygreenneighbor.com%3A24745%2Fauth%2Ffacebook%2Fcallback&scope=email%2Coffline_access&response_type=code
{
"error": {
"message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.",
"type": "OAuthException",
"code": 191
}
}
Thanks for your thoughts/guidance.
-S
After a lot of digging around, I cam across this article
http://www.kbedell.com/2011/03/08/overriding-omniauth-callback-url-for-twitter-or-facebook-oath-processing/
I realized that I had switched to using Passenger as my web server from a singled threaded/process WebRick webserver. Passenger has more than one process running on the same dyno and apparently it sends a callback url with a port number in the request. To override that I used the advice in the above article and set the following in my applicaiton.rb file
OmniAuth.config.full_host = "http://www.mygreenneighbor.com" and it solved the problem.
Hope this helps someone.
-S

redirect_uri and how to host callback.html on SoundCloud?

I am trying to access Soundcloud from a local HTML page on my laptop. I am stuck at the part of hosting "callback.html" as a redirect_uri. The script I am trying to run is the basic Authenication JavaScript from the Soundcloud documentation page:
<script src="http://connect.soundcloud.com/sdk.js"></script>
<script>
// initialize client with app credentials
SC.initialize({
client_id: 'my_client_id',
redirect_uri: 'http://127.0.0.1/Users/Maria/Documents/SoundcloudClient/callback.html'
});
// initiate auth popup
SC.connect(function() {
SC.get('/me', function(me) {
alert('Hello, ' + me.username);
});
});
</script>
This script gets me to the connect pop-up when I launch the page in Chrome and Firefox.
But, once I have logged in as a Soundcloud user, I get the following error:
Oops! Google Chrome could not connect to 127.0.0.1
If I change my redirect_uri to localhost I get the same error.
If I try:
files:///C:/Users/Maria/Documents/SoundcloudThinClient/callback.html
I get a similar error.
I also tried:
ocalhost:3000
and:
localhost:8080
even though I'm not sure what would be listening on those ports.
So, basically, I'm asking what path do I put for callback.html in order for this to work?
I confess I don't know how the redirct_uri actually functions. I looked at the Oauth pages for it, but I don't understand them. I am beginning to think that I can't simply create an HTML page, paste the JavaScript, create a callback.html file and have this work, even though the SC documentation seems to say that this is possible. If so, what steps am I missing?
I am beginning to attempt this. I believe you have to go to the developer site and sign up as having an app. The redirect uri is asked for and the form gives you an API key you can use in your app.
I'm using drupal so, perhaps adding the oath module and using Php to add the api key might work well.
I had the same problem and I think I solved it.
Morning-after-edit: I posted this dead-tired after working towards a solution through the night. Now, the day after, I realize that you were speaking about the general problem, whereof I face a very particular instance. The following only applies directly to registering soundcloudlabs' soundcloud-group-recorder: https://github.com/soundcloudlabs/soundcloud-group-recorder. There is probably a more general principle lurking behind there, though:
First: yes, you do have to register the app as your own at Soundcloud. At least I presumed so. And doing that, you must register correctly where on your server you will place the callback.html file. Take the ClientID assigned to your app and use that in the API intialize procedure.
Now, I'm a novice and know very little coding. But I started looking around in the main file, application.js.
At the top of the file there are two instances of client_id and redirect_uri each. I'm not sure if that serves a purpose or if one is technically superfluous. Through trial and error I found out that replacing the second instance of each with my own data worked.
Then there is groupId and groupUrl, both of which should contain your info, within quotation marks.
After a lot of trial and error, still having trouble getting the thing to run, I looked around and saw that, whereas early in the file, client_id was hooked within SC.initialize, redirect_uri was not. Under the line:
client_id: CLIENT_ID
I added:
redirect_uri: REDIRECT_URI
– with a customary comma in between. And that's it. It runs.

Trying to get OAuth dialog to work

I am at this step in getting my app started in the documentation:
https://developers.facebook.com/docs/appsonfacebook/tutorial/#auth
In there is a code block that (supposedly) forwards the user to a request dialog asking permission to access certain bit of information about them. I've placed this code block into the PHP script that my canvas URL points to, and changed the $app_id and $canvas_page to my application ID and canvas URL respectively. Instead of getting the expected dialog, I receive this following error from facebook:
"An error occurred. Please try again later."
No other details about the error are present. I've tried some variations of the script, and have even tried loading up this URL directly just to see if that would work. Note that I've replaced YOUR_APP_ID and YOUR_CANVAS_PAGE with the appropriate values and made sure that spelling and/or punctuation are correct:
https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_CANVAS_PAGE&scope=email,read_stream
For the redirect URL, I've tried prepending it with http://, https://, and no prefix at all. All with the same result.
My question: is the example in the documentation broken, or is the oauth link provided in the documentation currently down? The vague nature of the error is somewhat frustrating since I can't tell if it's something I'm doing wrong or if it's facebook's oauth function that's at fault.
So, the problem was that instead of using the numeric application ID that facebook assigned for me when I originally created the app as the YOUR_APP_ID parameter in the OAuth URL, I was using the application namespace string. Facebook didn't understand this sort of request, and returned the generic error message.
Once I used the numeric app ID, the OAuth dialog popped up to ask permission to access my account, as expected.

Facebook app oauth dialog error

I've been searching for the answer for days and I haven't been successful so I finally post to ask.
I'm developing a facebook app locally (it says I can develop locally in the guide) and having an issue when trying to authorize the app.
The following is the error msg I get when I direct to http://www.facebook.com/dialog/oauth?client_id=MY_APP_ID&redirect_uri=https://apps.facebook.com/MY_APP_NAME
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Error
An error occurred with Footmarker. Please try again later.
API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: Invalid redirect_uri: Given URL is not allowed by the Application configuration.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Canvas URL & Site URL : http://localhost:8888/app/
I'm using EasyPHP hence port 8888. I tried changing port number to 80(default), 8080(one used in facebook guide) and no success.
I don't know if it's EasyPHP that causes the problem or simply I'm doing something wrong.
This thing drives me crazy. Help much appreciated. Thanks.
in this url: http://www.facebook.com/dialog/oauth?client_id=MY_APP_ID&redirect_uri=https://apps.facebook.com/MY_APP_NAME
You have to set redirect_uri=http://localhost:8888/app and authorize the localhost domain in your facebook app's settings (in the App domains field).
The Site URL & Canvas URL are used to check if the redirect_uri is not set to another URL for security reasons but the standard specify redirect_uri so they've let this parameter.
It's for this kind of error I built OAuth.io. We don't want more developers like you with a headache using OAuth.
using it is really easy:
OAuth.popup('facebook', function(err, res) {
// here, you can use res.access_token to make your API Call
// or...
res.get('/me')
.done(function(data) {
alert('Hello ' + data.name)
})
})
With this, you can't make mistake with URL anymore :)
The problem here is that your URL is not on the Internet. It is accessible from your computer only. You need a public URL.
Perhaps you can use dynDNS free to get onto the Net with your application from home.
Or, get a web server connected to the Net to host your App.
Best of luck!
this just because of URL mistake
whatever website url is specified should be correct.
i mentioned website url as http://localhost:3000/ and domain as localhost
but in my browser i was running http://0.0.0.0:3000/ that was the actual problem so i ran server as localhost:3000 now its working fine. Because we mentioned site url as localhost fb will redirect to same, if we r running 0.0.0.0:3000 it will rise error that Given URL is not allowed by the Application configuration.
so becarefull with your website url you have specified in facebook app.
and the url you are running locally both should match
thank you

facebook OpenGraph API on Rails (FBGraph)

I am trying to use FBGraph to let my app publish messages on the users wall. However, all of the APIs are kind of foreign to me and I am just trying to change things and see what happens. Right now, I am getting this error message
{
"error": {
"type": "OAuthException",
"message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration."
}
}
Does anyone know what it means by redirect_uri? What would it be on my Application Settings page on facebook?
Florin is correct. Just a note here.. when testing locally you will need to set it to:
http://localhost:3000/ (or whatever your app server port is)
Then when you move it to production, set it to your regular URL:
http://yourdomain.com/
I have a separate facebook app that I use in development to test, so I don't have to change back and forth between them and I set up the keys in a settings file, which has my tokens for development and production apps.
Anyways, looks like you are almost there. It is making it back to the callback url at least. Should be fine once you update the facebook_connect URL
I am not a facebook expert, but I hit the exact same problem as you a few hours ago when I was trying to login a user inside a web application with Facebook.
It seems that the redirect_uri which you specify in your call to "https://graph.facebook.com/oauth/authorize" must be on the same domain as the Connect Url of your application. (you can set that connect url from the Connect section in your application's settings)
Regards,
Florin
May need to check your Settings > Basic > Basic Info > App Domain. I believe hat needs to be set correctly for the redirect_uri as well.
I had the same issue.
In my case, I had configured site url on facebook as: "http://localhost:3000", it was a wrong URL to facebook.
The reason is, it lack of the / in the end of url, so the correct site url should be:
"http://localhost:3000/"
Just verify your 'Application ID'. In my case I had that problem because I was using ID from my other project that I was working on. Fairly obvious but I lost some time.
I had to make sure I had the scope in there too:
config.omniauth :facebook, 'xxxx', 'xxx', :scope => 'offline_access,email,publish_stream'
Plus you really need to make sure you wait a couple of minutes because it does take time to propagate..