ERROR -- omniauth: (facebook) Authentication failure - ruby-on-rails

I'm getting the following error using the latest Omniauth Facebook gem:
ERROR -- omniauth: (facebook) Authentication failure! invalid_credentials: OAuth2::Error, :
My credentials are correct and i seem to hit facebook ok but the callback errors out.
Any ideas?

The problem I had was that my app was using an older version of the facebook API.
Omniauth-facebook uses a default API version, in my case 2.4 but my App needed a newer version because that is what it said in my Facebook Developer Console. In my case, all I had to do was to update the omniauth-facebook gem to version 4.0.
If you wish you can set the Facebook API version that you want to use instead of using the default like this (omniauth-facebook docs):
use OmniAuth::Builder do
provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'],
client_options: {
site: 'https://graph.facebook.com/v3.0', # this is the example API version
authorize_url: "https://www.facebook.com/v3.0/dialog/oauth"
}
end
You can check which API verison your app is using by going to your facebook developer console.
You can read more about the omniauth-facebook gem API here:
http://www.rubydoc.info/gems/omniauth-facebook/4.0.0#API_Version

I had the same problem but specifying version didn't help me. I end up passing token_params: { parse: :json } something like below which resolved my issue :
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, Figaro.env.fb_appid, Figaro.env.fb_sec,
{ scope: 'email', token_params: { parse: :json } }
end
I have found the reference #174 comment

If you are not using the gem as a middleware directly and instead configuring your options in config/initializers/devise.rb (like the guide in Devise's wiki suggests), you can solve this issue by adding token_params: { parse: :json } to your config options.
So, in config/initializers/devise.rb:
config.omniauth :facebook, "APP_ID", "APP_SECRET", token_params: { parse: :json }
This problem is explicitly handled in Devise's wiki linked above (see section "If you are seeing something like Could not authenticate you from Facebook because “Invalid credentials”...)

Please try to put as many details as you can, try to be specific about your issue to understand the issue more deeply. It'll help to find out the exact issue and answers.
As you're not specific with your issue. I am putting here my answer which I got after so many tries and research.
MY ERROR
ERROR -- omniauth: (facebook) Authentication failure! invalid_credentials: OAuth2::Error, {"message"=>"Cannot call API for app 67878******** on behalf of user sa97**********", "type"=>"OAuthException", "code"=>200, "fbtrace_id"=>"8987987*********"}:
I was facing the above issue in a case if the Facebook user who is authenticating itself by Signing up with his/her details is only having the mobile number in his Facebook profile and NO EMAIL ID because my app is validating the email id should be present before creating any User object.
Because the same code is working fine with the users having the email id in the profile.
Although the Facebook error should be more specific, which saves the developer time to debug the exact issue.

Related

Devise Oauth Twitter: OAuth::Unauthorized Forbidden 403

I am trying to implement Oauth Twitter using Devise.
I have created app on twitter
I have set callback url to: http://localhost:3000
I have added this to config\initializers\devise.rb
config.omniauth :twitter, "key", "key secret"
Sign in with Twitter automatically appears at this route: /users/sign_up/
But on clicking it I get this error
key and key secret are correct
I also tried deleting and creating new app.
I cannot get it fixed
Help would be greatly appreciated
Here it says that https needs to be setup.
So I followed This to set it up. But getting the same error
Turns out that in twitter app settings Callback URL Lock was set to Yes by default. Switching it to No fixed the error.
Thanks to kubido for helping me out to close the issue on github
You can try to add these in the Callback URLs in https://apps.twitter.com/
http://localhost:3000/auth/twitter/callback
http://127.0.0.1:3000/
http://127.0.0.1:3000/auth/twitter/callback
Worked for me after almost an hour!
I got these URLs after failing the log-in. I checked the request_options. One way to do it is using BetterErrors gem.
I had been facing the same issue,
eventually i fixed it by adding the following callbacks,
http://127.0.0.1:3000/auth/twitter/callback
http://127.0.0.1/
http://127.0.0.1/auth/twitter/callback
http://localhost:3000/auth/twitter/callback
and it worked like a charm,
You need set the callback url to: "Your url"/auth/twitter/callback

How to start work with Gmail API in Rails 4

I would like to add Gmail to my Rails 4 app. So far I have set up everything so user can log in with Google account. I followed this guide.
Now when user tries to log in my Rails 4 app he receives such onscreen :
After "Allow" user is redirected back to my Rails 4 app.
Initializers/omioauth.rb
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, Rails.application.secrets.client_id, Rails.application.secrets.client_secret, {scope: ['email',
'https://www.googleapis.com/auth/gmail.modify'],
access_type: 'offline', client_options: {ssl: {ca_file: Rails.root.join("cacert.pem").to_s}}}
end
All authorization data from Google is located in secrets.yml.
Installed gems:
gem "omniauth-google-oauth2", "~> 0.2.1"
gem "google-api-client"
Question: What are the next steps to implement Gmail API in Rails project? How to retrieve my Gmail inbox content..
So far I haven't found complete and self-explaining guide to do so.
I found Gmail gem, but the guide is very incomplete for Rails begginers.
For example, I installed this gem and then tried to require 'gmail' in rails c . Then I received error uninitialized constance 'gmail'.
Note: I don't need full solution to my problem,but just a push to start going and I could understand idea.
Thanks in advance.
Try to check the Ruby implementation of Gmail API in the Google Documentation itself.
Just complete the steps described in the rest of this page, and you'll have a simple Ruby command-line application that makes requests to the Gmail API.
For more information, you can also check these threads:
How to access the Gmail API with Ruby
google/google-api-ruby-client
Gmail API Client Library for Ruby
Gmail API and Rails – Authorize with OAuth via Omniauth

Error while login with Facebook and OAuth in ROR application

Ok, guys, I give up.
I create Rails app and want login with facebook.
I watch railscast, read a few tutorials and more then 20 questions on stackoverflow... but still i can't login with fb on my site..
so, please, help me with this problem...
Gemfile
gem 'omniauth-facebook'
gem 'koala', '~> 1.10.0rc'
config/initializers/omniauth.rb
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, Rails.application.secrets['APP_ID'], Rails.application.secrets['APP_SECRET'], { scope: 'user_about_me' }
end
index.html.slim
h2 Welcome
= link_to 'Login with Facebook', '/auth/facebook'
Facebook -> Developers -> MyApp -> Settigns
Basic:
Settings Advanced
And after 'Login with Facebook' link and confirm in popap I have error:
Given URL is not permitted by the Application configuration: One or
more of the given URLs is not permitted by the App's settings. It must
match the Website URL or Canvas URL, or the domain must be a subdomain
of one of the App's domains.
Can somebody explain me, what's wrong with Facebook or with my hands?
UPDATE:
ok, another error:
When Valid OAuth redirect URIs set to http://localhost:3000/auth/facebook/callback/, FACEBOOK respond with error Given URL is not permitted by the Application configuration: One or more of the given URLs is not permitted by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.
But when Valid OAuth redirect URIs set to http://localhost:3000/auth/facebook/callback (without '/' at the end), I have OAuth2 error: OAuth2::Error
: {"error":{"message":"Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request","type":"OAuthException","code":100,"fbtrace_id":"EYOCCnhlcFv"}}
It is currently broken. There is a pr out to fix the gem right now.
https://github.com/gioblu/omniauth-facebook/commit/eff97bfae32f72821cbccf0b48b78351e41eb585

Rails Facebook login error with omniauth-facebook - OmniAuth::Strategies::OAuth2::CallbackError

I'm trying to make Facebook login with omniauth-facebook in Rails 3.2.9; I have followed the steps of Ryan Bates in http://railscasts.com/episodes/360-facebook-authentication and in this very moment I have the same code.
If I try to login without the Javascript it works (it takes me to Facebook, I grant the permissions, and gets me back to the app successfully), but if I try with the Javascript (for the Facebook popup) it initially shows the popup to login, but then makes a redirect and throws me this error (without asking for the permissions):
Started GET "/auth/facebook/callback" for 127.0.0.1 at 2012-11-16 15:16:03 -0600
(facebook) Callback phase initiated.
(facebook) Authentication failure! invalid_credentials: OmniAuth::Strategies::OAuth2::CallbackError, OmniAuth::Strategies::OAuth2::CallbackError
OmniAuth::Strategies::OAuth2::CallbackError (OmniAuth::Strategies::OAuth2::CallbackError)
This is a very common error; I made the research and tried all the solutions (mostly are from some months ago) but none of them work. This is what I have tried:
Checking the sandbox in Facebook is disable (and I have waited hours for the propagation)
Checking the Site URL to http://localhost:3000/
Checking the App ID and App Secret
Downgrading the omniauth-facebook gem to 1.4, and throws me this error: omniauth-facebook must pass either acodeparameter or a signed request (viasigned_requestparameter or afbsr_XXXcookie)
Downgrade to Rails 3.2.8
What else should I do? (I think the key is in the Javascript, and right now I have the same code of the video, with CoffeeScript). Thanks in advance!
I followed that Railscast just now and managed to get it working. You'll notice people discussing your problem in the comments. Following the links there, I ended up on this issue on Github and this question on StackOverflow.
I recommend updating to 1.6.0 and to 2.0.0 when it finally comes out. In the meantime, make sure you aren't making any of these mistakes:
Defining your app credentials in two different initializers, usually omniauth.rb and devise.rb. source
Having a domain name mismatch between your live site and the site url configured within your facebook application. source
Leaving the facebook application in sandbox mode, so the domain name doesn't match the production one. source
Adding a before_filter :authenticate to the OmniauthCallbacksController or ApplicationController (since OmniauthCallbacksController inherits from ApplicationController). source
Using omniauth-facebook in conjunction with Facebook's client-side flow. source
Messing with the state param.
Solution without downgrading (using 1.5.1 right now) :
https://github.com/intridea/omniauth-oauth2/issues/32 ->
Add this to your provider declaration :
provider :facebook, xxxxxxxxx, yyyyyyyyy, {:provider_ignores_state => true}

omniauth-facebook gives "Error: An error occurred. Please try again later."

I have Ruby on Rails site. Users are allowed to login using their Facebook accounts. Its done using omniauth + omniauth-facebook gems.
All worked well, but afetr 30 oct facebook started to return "Error: An error occurred. Please try again later." message.
I think that issue linked with Removal of offline_access permission. But removing 'offline_access' from requested scope not solved the problem.
Here is the query omniauth redirects to:
https://www.facebook.com/dialog/permissions.request?app_id=239854476109563&display=page&next=http%3A%2F%2Fwww.inmyroom.ru%2Faccounts%2Fauth%2Ffacebook%2Fcallback&response_type=code&perms=email%2Coffline_access%2Cuser_birthday%2Cpublish_stream%2Cuser_photos%2Cuser_hometown%2Cuser_location%2Cuser_website&fbconnect=1
Any help. Thank you
UPDATE:
Oh, seems like I found the reason:
Sandbox mode was enabled automatically. And FB didn't allow me to disable it because my app have empty privacy policy url setting.
I found the reason: Sandbox mode was enabled automatically (and I wasn't notified). And FB didn't allow me to disable it because my app have empty privacy policy url setting.
in your omniauth.rb file
provider :facebook, 'fb_app_id', 'fb_app_secret',{:scope => 'email, publish_stream', :client_options => { :ssl => { :ca_file => "#{Rails.root}/config/ca-bundle.crt" } } }
and more info see railcast video
http://railscasts.com/episodes/360-facebook-authentication

Resources