2015년 12월 2일 수요일

amniauth facebook login setting probolem

Omniauth Facebook authentication on localhost



I am trying to set up Omniauth as described in this Railscast. While it works with Twitter, I am unable to get it working with Facebook. I also set up 'http://localhost:3000' as siteurl and 'localhost' as domain but still see the following error message in the browser:
Invalid redirect_uri: Given URL is not allowed by the Application configuration.
Does anyone of you have any suggestions on how to fix this? Thanks in advance.
shareimprove this question
   
I don't think I added any configuration except '0.0.0.0:3000/';. When you start up your local Rails server, what IP address does it say it's using? – monocle Jan 1 '11 at 1:11
   
It says 0.0.0.0:3000. What excactly did you add in your host file? – Ryan Foster Jan 1 '11 at 12:22 
   
I've never modified my hosts file. It has 127.0.0.1 for localhost. – monocle Jan 1 '11 at 15:49

5 Answers

up vote28down voteaccepted
Take a look at the redirect in the URI. Mine read localhost:3000 so I changed the Site URL to "http://localhost:3000/" and it worked.
shareimprove this answer
2 
Now it works! Thank your very much. After that i ran into this problem stackoverflow.com/questions/3977303/… . I followed the advise given in the answer and another error occured: No route matches "/auth/failure".. Hope to find a solution for that, too. – Ryan Foster Jan 1 '11 at 21:44 
2 
Is there any way to test in localhost and still have the app working on production environment? I mean, I can only access my app through facebook and I want to keep testing it locally without having to change the redirect destiny on Facebook. – Flavio Wuensche Oct 24 '12 at 21:43
1 
finally someone in stack with a perfect answer for this shit! thanks – Ricardo Vieira Apr 18 '13 at 21:41
1 
@fwuensche - You probably sorted this out, but easiest way is to just create two separate apps. You should store your key and secret as Environment Vars, this way you don't have the keys in your source code repo, and you can develop easily on localhost and production ;) – Louis Sayers Sep 14 '13 at 11:40
Here's what worked for me.
Right now Facebook does not allow setting the Site Domain to an IP, so it's not possible to set the Site URL to http://127.0.0.1:3000/ because then Facebook will complain that the URL does not match the domain.
So in your Facebook App set the:
Site URL: http://localhost:3000/
Domain: localhost
When you access the app on your dev machine make sure you type in localhost:3000 in the browser. If you use 127.0.0.1:3000 OmniAuth will use that in the callback url it sends to Facebook and then Facebook will throw the error Ryan mentions above.
shareimprove this answer
   
where are you supposed to set those? In which file? – kibaekr Jun 10 '12 at 3:35
   
   
Is there any way to test in localhost and still have the app working on production environment? I mean, I can only access my app through facebook and I want to keep testing it locally without having to change the redirect destiny on Facebook – Flavio Wuensche Oct 24 '12 at 21:44
I switch to http://lvh.me:3000 in my local browser to test facebook locally. Then in facebook app settings, make lvh.me your domain.
lvh.me is a registered domain pointing to 127.0.0.1 that a developer bought to test subdomains locally.
shareimprove this answer
   
Great tip. Thanks! – bikedorkseattle Feb 28 '13 at 22:53
Try using
http://0.0.0.0:3000/
for the 'Site URL'. This works for me. (Also, I don't have anything in the 'Site Domain' field.)
shareimprove this answer
   
still getting the same error after following your advise. did you add any line to your hostfile? i'm starting to lose my sanity because of this.. :( – Ryan Foster Dec 31 '10 at 7:45 
   
Rails finally not convert 127.0.0.1 into localhost, can grant access now, thanks. – Francis.TM Jul 12 '13 at 5:33
If you are on OSX you can use pow http://pow.cx/ to rename localhost to
http://yourapp-dev  
(is not really renamed, it's added)
you can set that as a valid domain name on facebook.
shareimprove this answer
3 
Have you tried that? Because I had a problem with it. Facebook didn't allow .dev address. – Shmidt Oct 9 '12 at 7:01

댓글 없음: