22

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.

Ryan Foster
  • 297
  • 1
  • 2
  • 10

5 Answers5

32

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.

Chrisjschmitt
  • 336
  • 2
  • 2
  • 2
    Now it works! Thank your very much. After that i ran into this problem http://stackoverflow.com/questions/3977303/omniauth-facebook-certificate-verify-failed . 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 01 '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
28

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.

shanethehat
  • 15,460
  • 11
  • 57
  • 87
Monica
  • 281
  • 2
  • 2
  • where are you supposed to set those? In which file? – kibaekr Jun 10 '12 at 03:35
  • @kibaekr in your facebook app's dashboard https://developers.facebook.com/apps/YOUR_APP_ID/summary – Naoise Golden Oct 21 '12 at 18:56
  • 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
15

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.

Josh Crews
  • 779
  • 2
  • 11
  • 21
7

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

monocle
  • 5,866
  • 2
  • 26
  • 22
  • 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 07:45
  • Rails finally not convert `127.0.0.1` into `localhost`, can grant access now, thanks. – Francis.TM Jul 12 '13 at 05:33
0

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.

Gonzalo S
  • 896
  • 11
  • 19
  • 3
    Have you tried that? Because I had a problem with it. Facebook didn't allow .dev address. – Shmidt Oct 09 '12 at 07:01