Facebook authentication problems with omniauth 0.2.6 rails ( invalid_credentials) - ruby-on-rails

I get an error when i try to login with facebook via omniauth gem ver.0.2.6.
It shows invalid_credentials.
http://localhost:3000/auth/failure?message=invalid_credentials
I use this code in initializer/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook,
"app_id",
"app_secret",
{:scope=>[:email,:user_birthday],:client_options => {:ssl => {:ca_path => "/etc/ssl/certs"}} }
end
Started GET "/auth/facebook" for 127.0.0.1
Started GET "/auth/facebook/callback?code=0b49kydcswTkMNfx_C9BwhE0Z-g9kO_oE0aJ2F4ghy0.eyJpdiI6IjlYaXRxTF9NdFBGbWtBUk9ZUXVSdUEifQ.DsDgdFUpuC6Z_B_m8j1MiAN1cQRS_Mcr9VvvZvSurs0wUyCRAvjDDEYjE6b6_VUF0KNkeLUy9lJCF2IF2BBGOeAt95fggdI49jZKwqo842z3cdsJQ2kZTQcQrs0jinxn" for 127.0.0.1
This all i get. I double checked app_id and app_secret all is ok and tried php version it works fine. So there is no error in this.
So how i can find more info about an error at least ? or how this problem can be fixed ?

Related

Linkedin Omniauth gem 'omniauth-linkedin-oauth2' giving Authentication failure! invalid_credentials: OAuth2::Error

I have an application running with successful Google and Facebook omniauthentication running. I want to add Linkedin Login too with omniauth. All seems to fine until I request the email address by adding :scope => 'r_emailaddress' to the line
devise.rb
config.omniauth :linkedin, ENV['LINKEDIN_CLIENT_ID'], ENV['LINKEDIN_CLIENT_SECRET'], :scope => 'r_emailaddress', :fields => ['email', 'id', 'first-name', 'last-name']
All seems to be correct if I removed the r_emailaddress and add any other scope like r_liteprofile as
config.omniauth :linkedin, ENV['LINKEDIN_CLIENT_ID'], ENV['LINKEDIN_CLIENT_SECRET'], :scope => 'r_liteprofile', :fields => ['email', 'id', 'first-name', 'last-name']
Gemfile
gem 'omniauth-linkedin-oauth2'
The error is coming up in the backend and in the front end after successfully putting all the credentials on the Linkedin page, the app is redirecting to the home page and not giving any error in the UI.
The error it's throwing in the logs is
ERROR -- omniauth: (linkedin) Authentication failure! invalid_credentials: OAuth2::Error, :
{"serviceErrorCode":100,"message":"Not enough permissions to access: GET /me","status":403}
It would be great if anyone can help me in this matter.
Remove scope and fields both and try this:
config.omniauth :linkedin, ENV['LINKEDIN_CLIENT_ID'], ENV['LINKEDIN_CLIENT_SECRET']

OAuth2::Error redirect_uri_mismatch using omniauth-google-oauth2 gem

I'm getting this error: OAuth2::Error redirect_uri_mismatch
This is how I have omniauth.rb set up, per omniauth-google-oauth2's documentation.
# config/initializers/omniauth.rb
OmniAuth.config.logger = Rails.logger
OmniAuth.config.full_host = Rails.env.production? ? 'https://www.********.org' : 'http://localhost:3000'
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_OAUTH_CLIENT_ID'], ENV['FACEBOOK_OAUTH_SECRET']
provider :google_oauth2, ENV['GOOGLE_OAUTH_CLIENT_ID'], ENV['GOOGLE_OAUTH_SECRET'], {scope: 'profile', image_aspect_ratio: 'square', image_size: 48, access_type: 'online'}
end
And this is how I have my routes.rb set up to handle the callback:
# config/routes.rb
get 'auth/:provider/callback', to: 'sessions#create'
Here's a screenshot of my Google Developer Console, where I have my authorized redirect uri set up as http://localhost:3000/auth/google_oauth2/callback.
I have tried it as just http://localhost:3000 and with https and http://localhost/auth/google_oauth2/callback and several other variations.
Some people say the console can take a while to update, so I wonder if it's possible I tried the correct thing at some point and didn't give it enough time (more than 5 minutes?) to update.
Facebook's callback (http://localhost:3000/auth/facebook/callback at the Facebook developer console) works, taking me all the way through to the SessionsController's #create action, where I haven't added a way to handle it yet, so it's throwing an error there.
Can anyone spot what I'm doing wrong!?

Conditionals app_id for omniauth.rb. Localhost and heroku without changing omniauth.rb

I've got a rails 4 application with facebook authentication and I've deployed it on heroku.
Sometimes i debug my app using localhost. That's why I create two apps on facebook developers page - the first using heroku_address (app_id 1 and app_secret 1) and the second one using localhost_address (app_id 2 and app_secret 2).
My question is how should I configure my omniauth.rb so that my_rails_app will use app_id 1 set if heroku_adress or app_id 2 set if localhost. I would like my appliction_authentication to work both on localhost and on heroku_url without changing omniauth.rb.
Here is my omniauth.rb:
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, '229517473864398', '88c42ceadf5ac4baeb36333a5fc990ac' #, {:client_options => {:ssl => {:ca_path => "/etc/ssl/certs"}}}
# provider :facebook, '1397526230476094', '5fd1171c4781525b9e5a873c095f4d6e' #, {:client_options => {:ssl => {:ca_path => "/etc/ssl/certs"}}}
end
end
Thanks in advance for your attention!
The best way is to put those information in ENV. It's easy to do with heroku, use the figaro gem if needed.

SSL certificate issue with implementing facebook login via Omniauth - Windows machines

I am facing the same issue as described here -
OmniAuth & Facebook: certificate verify failed
The most voted answer suggests adding the following to your Omniauth initializer:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, FACEBOOK_KEY, FACEBOOK_SECRET, {:client_options => {:ssl => {:ca_path => "/etc/ssl/certs"}}}
end
However he mentions "/etc/ssl/certs" is the CA_PATH for ubuntu.
What is the relevant CA_PATH for an windows ?
If there is no certificate on my machine , how do I install one and where do I put the certificate file ?
This is how I solved the issue -
I downloaded this file - http://certifie.com/ca-bundle/ca-bundle.crt.txt and put in my app/config folder.
I renamed the file as ca-bundle.crt
I updated my omniauth initializer to relfect the following -
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, FACEBOOK_KEY, FACEBOOK_SECRET, :client_options => { :ssl => { :ca_file => "#{Rails.root}/config/ca-bundle.crt" } }
end
And it worked.

devise + omniauth auth/failure?message=invalid_credentials

after i added an application in twitter when i request for an authentication in twitter (/auth/twitter) i get these error message
http://localhost:3000/auth/failure?message=invalid_credentials
Routing Error
No route matches "/auth/failure"
how can i add a valid credential or is there any ssl certificate that must be included in requesting for twitter auth??
my facebook authentication just works fine after i added a parameter ssl certificate that looks like this
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook,'xxx', 'xx', { :scope => 'publish_stream,offline_access,email',:client_options => { :ssl =>{ :ca_path => "/etc/ssl/certs" } }}
provider :twitter, 'xx','xxx' #,{ :client_options => { :ssl =>{ :ca_path => "/etc/ssl/certs" } }}
end
i've same problem with you, it happen because oauth_token in twitter login only valid on once request. May be your application trying to refresh when authentication to twitter.
when i've problem like you, my apps trying to refresh the webpage with
window.opener.location = "#{request.fullpath}";
Until now i'couldn't find how to popup a window when login using twitter. I'm using omniauth and rails 3.0.3. Thanks
This is all you need
site url http://localhost:3000/

Resources