我有authlogic和authlogic_facebook_connect配置的應用程序,但我每次點擊的時間來「連接」按鈕,我UserSession驗證失敗,他說:「你沒有提供身份驗證的任何細節」Authlogic Facebook連接天翻地覆
」不是個authlogic_facebook_connect應該繞過登錄/密碼認證?我是否缺少一些配置步驟?
任何幫助,將不勝感激!
我有authlogic和authlogic_facebook_connect配置的應用程序,但我每次點擊的時間來「連接」按鈕,我UserSession驗證失敗,他說:「你沒有提供身份驗證的任何細節」Authlogic Facebook連接天翻地覆
」不是個authlogic_facebook_connect應該繞過登錄/密碼認證?我是否缺少一些配置步驟?
任何幫助,將不勝感激!
嘿,也許我可以幫上這一條,只是有這個問題不是很長一段時間以前...
連接Facebook已經過時。所有酷酷的孩子現在都在使用帶有OAuth的Facebook Graph。 Facebook團隊甚至已經關閉了Facebook Connect的文檔。
無論如何,這是Authlogic Facebook連接,它只是不工作了。
最後,我一直使用Authlogic進行正常的登錄和帳戶管理,但對於Facebook連接,我編寫了自己的代碼。
你可能已經使用過facebooker gem。卸載那個gem,但保留config/facebooker.yml文件。
試試這個:通過增加配置/初始化/ load_config.rb這裏面的代碼使用config/facebooker.yml
保持(你需要創建這個文件)
config = YAML.load_file("#{Rails.root}/config/facebooker.yml") || {}
facebook_config = config['common'] || {}
facebook_config.update(config[Rails.env] || {})
FB_CONFIG = facebook_config.symbolize_keys
添加該代碼的user_controller.rb內:
def facebook_oauth_callback if not params[:code].nil? callback = url_for(:host => APP_CONFIG[:host], :controller => 'gallery/user', :action => 'facebook_oauth_callback') url = URI.parse("https://graph.facebook.com/oauth/access_token?client_id=#{FB_CONFIG[:application_id]}&redirect_uri=#{callback}&client_secret=#{FB_CONFIG[:secret_key]}&code=#{CGI::escape(params[:code])}") http = Net::HTTP.new(url.host, url.port) http.use_ssl = (url.scheme == 'https') tmp_url = url.path + "?" + url.query request = Net::HTTP::Get.new(tmp_url) response = http.request(request) data = response.body access_token = data.split("=")[1] if access_token.blank? flash[:notice] = 'An error occurred while connecting through Facebook, please try again later.' else url = URI.parse("https://graph.facebook.com/me?access_token=#{CGI::escape(access_token)}") http = Net::HTTP.new(url.host, url.port) http.use_ssl = (url.scheme == 'https') tmp_url = url.path + "?" + url.query request = Net::HTTP::Get.new(tmp_url) response = http.request(request) user_data = response.body user_data_obj = JSON.parse(user_data) @user = User.new_or_find_by_facebook_oauth_access_token(access_token, {:user_data => user_data_obj}) if @user.new_record? session[:user] = @user session[:external_app] = "Facebook" redirect_to(:action => 'new_details') else user_session = UserSession.create(@user) flash[:notice] = "Successfully logged in." redirect_back_or_default root_url end end end end def create_facebook redirect_to("https://graph.facebook.com/oauth/authorize?client_id=#{FB_CONFIG[:application_id]}&redirect_uri=" + url_for(:host => APP_CONFIG[:host], :controller => 'gallery/user', :action => 'facebook_oauth_callback') + "&scope=email,offline_access") end
def self.new_or_find_by_facebook_oauth_access_token(access_token, options = {}) user = User.find_by_facebook_oauth_access_token(access_token) if user.blank? #code to create new user here end user end
添加鏈接到行動create_facebook在視圖中,類似
<%= link_to image_tag('gallery/button-facebook.png', :title => "register with Facebook", :alt => "register with Facebook"), {:action => 'create_facebook'}, {:target => '_parent'} %>
說明
該代碼只適用於我的項目,不只是複製粘貼,而是逐行學習。隨着時間的推移,我意識到使用簡單的代碼可以更好地理解,而不是使用其他複雜的插件,當事情出錯時您無法修復它們。
我有這個問題,我覺得我的問題是在我的呼籲
<%= authlogic_facebook_login_button :controller => 'account', :js => :jquery %>
注意到我在控制器通過。無論如何,我認爲這是我的解決方案,現在我正在通過Facebook進行身份驗證,現在又擊中了另一個問題,但它每次都會在我的網站上創建一個新用戶。
你有沒有得到這個地方? – Codebeef 2010-03-16 19:43:20
不,當我回到它時,我會嘗試http://github.com/GICodeWarrior/authlogic_facebook而不是http://github.com/kalasjocke/authlogic_facebook_connect希望從長遠來看它會更好地工作。 – a10s 2010-03-17 21:29:57