Bolo
Bolo

Reputation: 2788

invalid_credentials with omniauth on heroku

I implemented a project configured with OmniAuth/Twitter and OmniAuth/Facebook. in development mode with any problem.

But when i tried on heroku. it refused to work.

 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 logs

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

Thanks

Upvotes: 1

Views: 1102

Answers (1)

AJcodez
AJcodez

Reputation: 34234

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..

Upvotes: 3

Related Questions