我收到以下错误:
"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}}}
Facebook配置:
的routes.rb
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
devise_scope :user do
get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end
我已经尝试过以下方法:
方法1:
OmniAuth.config.full_host = '`http://localhost:3000/`'
这是我最接近的,因为它重定向我,但地址是http://localhost:3000//users/auth/facebook/callbacks?xxx
我已经尝试过没有最后一个斜线OmniAuth.config.full_host = 'http://localhost:3000'
,但后来我得到了191。
方法2
正常的初始化程序,没有黑客攻击。
方法3
在Facebook配置页面中设置域名。
方法4
将 App Domains 设置为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的失败方法中,用于处理回调。
如果您知道其他替代方案或希望看到其他任何可以帮助我的信息,请随时提问或回答。
答案 0 :(得分:1)
Facebook不允许重定向地址为localhost。您必须使用真实的IP地址或命名地址。 查看类似问题的答案:Facebook app - login through omniauth - OAuthException 191
答案 1 :(得分:0)
正如@Ashitaka所提到的,我必须删除旧的并且已弃用的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}}}
Facebook配置:
![在此处输入图片说明] [1]
链接到Facebook身份验证
/users/auth/facebook
感谢您的帮助,这个问题花了我5个小时才解决。