2013-04-23 74 views
2

我使用https://github.com/plataformatec/devise/wiki/OmniAuth%3a-Overview集成omniauth Facebook的無法從Facebook驗證您的身份。但我得到的錯誤:Rails的:因爲「證書無效」

Could not authenticate you from Facebook because "Invalid credentials". 

我有設計安裝。當我點擊Facebook登錄鏈接時,它會將我重定向到Facebook登錄。當我輸入我的詳細信息時,它會回到設計標誌並給出上述錯誤。我在https://github.com/plataformatec/devise/wiki/OmniAuth%3a-Overview上檢查了「Invalid credentials」的解決方案,我的應用是爲App Type = Web設置的頭文件。沒有得到它爲什麼不工作。

而且我的應用程序上線,但尚未從Facebook批准。但我不認爲它與這個錯誤有關。以下是東西我做了omniauth Facebook的:

Gemfile中包含:

gem 'omniauth' 
gem 'omniauth-facebook', '1.4.0' 

在用戶模型,補充說:

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" 

鏈接facebook sign_in:

<%= link_to "Sign in with Facebook", user_omniauth_authorize_path(:facebook) %> 

route.rb:

devise_for:用戶,:控制器=> {:omniauth_callbacks => 「omniauth_callbacks」}

Omniauth控制器:

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 

可以在這個人的幫助?

+0

我不知道這件事,但可能是因爲你的電子郵件地址在你的omniauth範圍之內有空間嗎? 我有同樣的錯誤由於一個錯字 – golfadas 2013-08-21 13:33:59

+0

可能重複[Rails的:無法從Facebook驗證您的身份,因爲「無效憑證」(http://stackoverflow.com/questions/16176208/rails-could-not-authenticate- you-from-facebook-because-invalid-credentials) – mindriot 2014-09-02 08:08:21

+0

這已被標記爲您發佈的具有更多信息的相同問題的副本。將來如果您有其他信息要添加到問題中,請編輯現有問題,而不是開始新問題。對於omniauth-facebook(1.4.0), – mindriot 2014-09-02 08:17:57

回答

1

嘗試清除瀏覽器cookies。有時omniauth不會僅僅因爲你必須刪除你的瀏覽器cookies而工作。

的另一件事可能是該版本是不正確的。

這個問題似乎是依賴關係。在1.4.0它需要 omniauth-的oauth2 1.0.3和1.4.1在它需要omniauth-OAuth的1.1.x版本

爲在這裏看到:https://github.com/intridea/omniauth/issues/276

+0

版本是omniauth-oauth2(1.0.2)。它可以或應該是1.0.3? – user2206724 2013-04-23 07:28:45

+0

只是嘗試儘可能地更新所有。這可以工作。但我不確定。 – 2013-04-23 07:29:37

+0

清除了cookie,我嘗試使用sudo gem install omniauth-oauth2 --version 1.0.3進行升級。但它仍然是1.0.2。獲取相同的錯誤。 – user2206724 2013-04-23 08:45:09