1

我实现了一个配置了 OmniAuth/Twitter 和 OmniAuth/Facebook 的项目。在开发模式有任何问题。

但是当我尝试使用heroku时。它拒绝工作。

 use Rack::Session::Cookie
  use OmniAuth::Builder do
    provider :twitter, ENV['TWITTER_APP_ID'], ENV['TWITTER_SECRET']
    provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET'], :scope => 'email'
  end

Heroku 日志

012-11-02T03:28:47+00:00 app[web.1]: E, [2012-11-02T03:28:47.339453 #58] ERROR -- omniauth: (twitter) Authentication failure! invalid_credentials: OAuth::Unauthorized, 401 Unauthorized
2012-11-02T03:28:47+00:00 heroku[router]: GET p####.herokuapp.com/auth/twitter/callback?oauth_token=r6l3GpwmxH38W8Q9WltcWs9PqyyGxxiGAUqXGFhmKs&oauth_verifier=O9HD6jLaEL1aRUcORIebGEZIQHbqtcgB012q5aZlCE dyno=web.1 queue=0 wait=0ms service=368ms status=302 bytes=9
2012-11-02T03:28:47+00:00 app[web.1]: 92.160.179.137 - - [02/Nov/2012 03:28:47] "GET /auth/failure?message=invalid_credentials&origin=https%3A%2F%2F p####.herokuapp.com%2Flogin&strategy=twitter HTTP/1.1" 200 3160 0.0033
2012-11-02T03:28:47+00:00 heroku[router]: GET  p####.herokuapp.com/auth/failure?message=invalid_credentials&origin=https%3A%2F%2F p####.herokuapp.com%2Flogin&strategy=twitter dyno=web.1 queue=0 wait=0ms service=8ms status=200 bytes=3160

谢谢

4

1 回答 1

3

A few things. Run $ heroku config and make sure the right keys are on Heroku.

Also, not sure about Twitter, but Facebook requires a callback url that you put in the settings for your app on developer.facebook.com, and that needs to point to the heroku url or it will be invalid.

Another long shot, but it could be an issue with CA certificates. I had that problem and fixed it with this in an initializer:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET'], { 
    client_options: { ssl: { 
        ca_file: '/usr/lib/ssl/certs/ca-certificates.crt',
        ca_path: "/etc/ssl/certs"
    }}
  }
end

Hope this helps some..

于 2012-11-04T11:17:29.197 回答