Reputation: 1365
I integrated omniauth-facebook using https://github.com/plataformatec/devise/wiki/OmniAuth%3a-Overview. But I am getting error of :
Could not authenticate you from Facebook because "Invalid credentials".
I have devise installed. When i click on facebook sign in link, it redirects me to facebook login. When i enter my details, it comes back to devise sign and gives above error. I checked the solution for "Invalid credentials" on https://github.com/plataformatec/devise/wiki/OmniAuth%3a-Overview and my app is header set for App Type = Web. Not getting why it is not working.
Also my app is live but yet to approve from facebook. But i don't think it is related to this error. Following are the things i did for omniauth-facebook:
Gemfile contains:
gem 'omniauth'
gem 'omniauth-facebook', '1.4.0'
In user model, added:
devise :omniauthable, :omniauth_providers => [:facebook]
attr_accessible :provider, :uid
def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
user = User.where(:provider => auth.provider, :uid => auth.uid).first
unless user
user = User.create(name:auth.extra.raw_info.name,
provider:auth.provider,
uid:auth.uid,
email:auth.info.email,
password:Devise.friendly_token[0,20]
)
end
user
end
devise.rb
require "omniauth-facebook"
config.omniauth :facebook, "APP_ID", "APP_SECRET", :scope => "offline_access, email"
Link for facebook sign_in:
<%= link_to "Sign in with Facebook", user_omniauth_authorize_path(:facebook) %>
route.rb:
devise_for :user, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }
Omniauth controller:
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
@user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)
if @user.persisted?
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
Can anybody help in this?
Upvotes: 2
Views: 2426
Reputation: 5784
Try to clear your browser cookies. sometimes omniauth won't work just because you have to delete your browser cookies.
an other thing could be that the version isn't right.
The problem seems to be the dependencies. At 1.4.0 it requires omniauth-oauth2 1.0.3, and at 1.4.1 it required omniauth-oauth 1.1.x
as seen here: https://github.com/intridea/omniauth/issues/276
Upvotes: 1