Ruby on Rails omniauth-facebook在开发中工作,但在Heroku上生产失败

时间:2013-08-27 23:18:28

标签: ruby-on-rails ruby facebook heroku omniauth

我在我的应用中使用omniauth-facebook。一切都很好地发展。一旦我上传到heroku(我制作了另一个Facebook应用程序,以补偿生产中的URL更改)。我可以使用mysitename.heroku.com/auth/facebook进入facebook登录页面。但是,在我登录并单击“接受/允许”按钮后,出现故障并且处理了OmniAuth.config.on_failure函数,然后转到我的错误屏幕。

我在.on_failure函数中执行[200,{},[env [' omniauth.error']。inspect]]时出现的错误:

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

以下是与命令相关的日志:heroku logs

2013-08-27T22:44:20.842352+00:00 app[web.1]: Started GET "/auth/facebook" for 174.21.250.137 at 2013-08-27 22:44:20 +0000
2013-08-27T22:44:20.857734+00:00 heroku[router]: at=info method=GET path=/auth/facebook host=warm-anchorage-4172.herokuapp.com fwd="174.21.250.137" dyno=web.1 connect=10ms service=26ms status=302 bytes=262
2013-08-27T22:44:21.229031+00:00 heroku[web.1]: Stopping remaining processes with SIGKILL
2013-08-27T22:44:21.228882+00:00 heroku[web.1]: Error R12 (Exit timeout) -> At least one process failed to exit within 10 seconds of SIGTERM
2013-08-27T22:44:21.609111+00:00 app[web.1]: Started GET "/auth/facebook/callback?code=AQD4g5_eZRBzwOOvl_qI64mnKtk1b4048YuGXVyBjfxer9QrSBgiMwL8Nxsr0yducrL1DMfK3EdNS5E8qljb7BWvSoIoysfXF3tbIs6_7VkV2LiRVfrmZ8goku1MweG46hagJtatAJTbVfZkE6VL4t-pX169DCrn6TRhkfJoNAnRF8Xs2wHbPg1pwsUOOi_BJdRXNx9noZ8Cnc51unUVVKez-MStbD9OfDST5PNZNJzZJhaXiC_K2JpTg2S2z8tptsEAFf-gV5Rim86tN66FTCLG-HVhKBHp3bJgiYdC0160Kp8m0oKrO9lwMJQr6NBTOSw&state=fd82e1208e9848d0deda8271118799c38c4350f9c9f95fc6" for 174.21.250.137 at 2013-08-27 22:44:21 +0000
2013-08-27T22:44:21.609111+00:00 app[web.1]: Started GET "/auth/facebook/callback?code=AQD4g5_eZRBzwOOvl_qI64mnKtk1b404YuGXVyBjfxer9QrSBgiMwL8Nxsr0yducrL1DMfK3EdNS5E8qljb7BWvSoIoysfXF3tbIs6_7VkV2LiRVfrmZ8goku1MweG46hagJtatAJTbVfZkE6VL4t-pX169DCrn6TRhkfJoNAnRF8Xs2wHbPg1pwsUOOi_BJdRXNx9noZ8Cnc51unUVVKez-MStbD9OfDST5PNZNJzZJhaXiC_K2JpTg2S2z8tptsEAFf-gV5Rim86tN66FTCLG-HVhKBHp3bJgiYdC0160Kp8m0oKrO9lwMJQr6NBTOSwstate=fd82e1208e9848d0deda8271118799c38c4350f9c995fc6" for 174.21.250.137 at 2013-08-27 22:44:21 +0000
2013-08-27T22:44:21.700789+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path=/auth/facebook/callback?code=AQD4g5_eZRBzwOOvl_qI64mnKtk1b4048YuGXVyBjfxer9QrSBgiMwL8Nxsr0yducrL1DMfK3EdNS5E8qljb7BWvSoIoysfXF3tbIs6_7VkV2LiRVfrmZ8goku1MweG46hagJtatAJTbVfZkE6VL4t-pX169DCrn6TRhkfJoNAnRF8Xs2wHbPg1pwsUOOi_BJdRXNx9noZ8Cnc51unUVVKez-MStbD9OfDST5PNZNJzZJhaXiC_K2JpTg2S2z8tptsEAFf-gV5Rim86tN66FTCLG-HVhKBHp3bJgiYdC0160Kp8m0oKrO9lwMJQr6NBTOSw&state=fd82e1208e9848d0deda8271118799c38c4350f9c9f95fc6 host=warm-anchorage-4172.herokuapp.com fwd="174.21.250.137" dyno=web.1 connect=2ms service=114ms status=503 bytes=0
2013-08-27T22:44:22.939414+00:00 heroku[web.1]: Process exited with status 137
2013-08-27T22:44:34.222678+00:00 app[web.1]: [2013-08-27 22:44:34] INFO  WEBrick 1.3.1
2013-08-27T22:44:34.222781+00:00 app[web.1]: [2013-08-27 22:44:34] INFO WEBrick::HTTPServer#start: pid=2 port=13228
2013-08-27T22:44:34.222678+00:00 app[web.1]: [2013-08-27 22:44:34] INFO  ruby 1.9.3   (2013-06-27) [x86_64-linux]

这是我的omniauth.rb的样子:

OmniAuth.config.logger = Rails.logger

Rails.application.config.middleware.use OmniAuth::Builder do
  if Rails.env.production?
    provider :facebook, "********72531693", "*******32c00b6bd32b70fa939e6a7c1"
    {:scope => 'PERMISSION_1, PERMISSION_2, PERMISSION_3...', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}
  end
    provider :facebook, "********45876931", "*******2abe337c16c135f06404c91a"
    {:scope => 'PERMISSION_1, PERMISSION_2, PERMISSION_3...', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}
end

OmniAuth.config.on_failure = Proc.new do |env|
  UsersController.action(:omniauth_failure).call(env)
  #this will invoke the omniauth_failure action in UsersController.
end

所以我不确定,但我对自己的问题非常有信心,因为它在我的localhost:3000上完美开发。我的应用程序在我的开发和生产版本除了主机网址之外几乎完全相同。由于我至少可以尝试登录,因此我认为它与facebook设置无关。我尝试使用omniauth-facebook 1.4.0和1.4.1。

添加我的路线文件,以防万一有人看到我看不到的东西。

root  'welcome#index'
match '/signup',  to: 'users#new',  via: 'get'
match '/signin',  to: 'sessions#new', via: 'get'
match '/signout',  to: 'sessions#destroy', via: 'delete'
match '/about', to: 'static_pages#about', via: 'get'
match '/help', to: 'static_pages#help', via: 'get'
match '/auth/:provider/callback', to: 'sessions#createfb', via: 'get'

1 个答案:

答案 0 :(得分:1)

我很确定您已将Facebook应用程序设置为使用“localhost”或某些开发服务器URL作为回调。它在生产中失败,因为生产服务器的URL未配置为应用程序的一部分。检查应用设置。

编辑:我可以看到一个名为“Facebook登录网站”的部分,其中有一个名为“网站网址”的字段。您确定没有将其设置为localhost:3000吗?