3

问题

我收到以下错误:

"error": {
      "message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.",
      "type": "OAuthException",
      "code": 191
   }

这是众所周知的,我找到了许多不同的解决方案来解决它,不幸的是,它们中的任何一个都为我工作。

我试图让它在本地运行localhost:3000,但不能让它工作。

我的配置是普通配置:

配置/初始化程序/devise.rb

config.omniauth :facebook, '396783260390829', 'a504939e60c3410ed1becc44f41d4b94', {client_options: {ssl: {ca_file: Rails.root.join('lib/assets/cacert.pem').to_s}}}

脸书配置:

在此处输入图像描述

路由.rb

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

devise_scope :user do
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end

我已经尝试了以下方法:

方法一:

OmniAuth.config.full_host = '`http://localhost:3000/`'

这个是我得到的最接近的,因为它把我重定向回来,但地址是 http://localhost:3000//users/auth/facebook/callbacks?xxx

我已经尝试不使用最后一个斜线OmniAuth.config.full_host = 'http://localhost:3000',但后来我得到了 191。

方法二

普通初始化程序,没有破解。

方法 3

在 Facebook 配置页面中设置域。

方法 4

应用程序域设置为 localhost

方法 5

将 Facebook 配置中的网站设置为http://localhost:3000/users/auth/facebook

方法 6

尝试使用我的 ip 地址而不是 localhost 并得到相同的错误,但不是在失败OmniauthCallbacksController,而是在graph.facebook.com/oauth/authorize?

redirect_uri=http://localhost:3000/users/auth/facebook/callback

所有方法的结果

在所有情况下,除了我内联解释的情况外,我得到了

OAuthException 191

在我为处理回调而创建的 OmniauthCallbackController 的失败方法中。

如果您知道其他选择或想看到其他任何东西来帮助我,请随时提问或回答。


4

2 回答 2

1

Facebook 不允许重定向地址为 localhost。您必须使用真实 IP 地址或命名地址。查看类似问题的答案:Facebook 应用程序 - 通过omniauth 登录 - OAuthException 191

于 2013-02-05T00:52:56.940 回答
0

解决方案

正如@AshitakaI 所提到的,我必须删除我的 old 和 deprecated omniauth.rb,所以我的最终和工作配置如下:

配置/初始化程序/devise.rb

为了进行身份验证,我将 cacert 复制到我的资产中并在devise.rb

config.omniauth :facebook, 'xxxxxxxxxxxxxxx', 'a504xxxe60cxxxxed1bexxxxf41d4b94', {client_options: {ssl: {ca_file: Rails.root.join('lib/assets/cacert.pem').to_s}}}

脸书配置:

![在此处输入图像描述][1]

链接到 Facebook 身份验证

/users/auth/facebook

感谢您的帮助,这个问题花了我 5 个小时才解决。

于 2013-08-30T01:43:27.387 回答