Ruby-on-rails 本地主机上的 Omniauth Facebook 身份验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4567158/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Omniauth Facebook authentication on localhost
提问by Ryan Foster
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:
我正在尝试按照Railscast 中的描述设置 Omniauth 。虽然它适用于 Twitter,但我无法让它与 Facebook 一起使用。我还设置了 ' http://localhost:3000' 作为 siteurl 和 'localhost' 作为域,但仍然在浏览器中看到以下错误消息:
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.
你们中有人对如何解决这个问题有任何建议吗?提前致谢。
回答by Chrisjschmitt
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.
查看 URI 中的重定向。我的读取 localhost:3000 所以我将站点 URL 更改为“http://localhost:3000/”并且它起作用了。
回答by Monica
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.
现在 Facebook 不允许将站点域设置为 IP,因此无法将站点 URL 设置为 IP,http://127.0.0.1:3000/因为 Facebook 会抱怨 URL 与域不匹配。
So in your Facebook App set the:
所以在你的 Facebook 应用程序中设置:
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.
当您在开发机器上访问应用程序时,请确保在浏览器中输入 localhost:3000。如果您使用 127.0.0.1:3000 OmniAuth 将在它发送到 Facebook 的回调 url 中使用它,然后 Facebook 将抛出上面 Ryan 提到的错误。
回答by Josh Crews
I switch to http://lvh.me:3000in my local browser to test facebook locally. Then in facebook app settings, make lvh.me your domain.
我在本地浏览器中切换到http://lvh.me:3000以在本地测试 facebook。然后在 facebook 应用程序设置中,将 lvh.me 设为您的域。
lvh.me is a registered domain pointing to 127.0.0.1 that a developer bought to test subdomains locally.
lvh.me 是指向 127.0.0.1 的注册域名,开发人员购买该域名是为了在本地测试子域名。
回答by monocle
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.)
对于“站点 URL”。这对我有用。(此外,我在“站点域”字段中没有任何内容。)
回答by Gonzalo S
If you are on OSX you can use pow http://pow.cx/to rename localhost to
如果您使用的是 OSX,则可以使用 pow http://pow.cx/将 localhost 重命名为
http://yourapp-dev
(is not really renamed, it's added)
(没有真正重命名,它是添加的)
you can set that as a valid domain name on facebook.
您可以将其设置为 Facebook 上的有效域名。

