簡體   English   中英

Omniauth Twitter回調后為空會話

[英]Empty Session after Omniauth Twitter Callback

我正在嘗試構建使用OmniAuth gem的應用程序,以便Twitter用戶可以登錄。

我遵循了教程中的步驟,我很確定自己做對了所有事情。

但是在Twitter的回調中,我得到了這個臭名昭著的錯誤消息:

NoMethodError
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]

在深入研究omniauth gem之后,我發現,在OAuth#callback_phase ,會話不包含任何oauth信息

def callback_phase
    ::Rails.logger.info "session: #{session.inspect}"
    ::Rails.logger.info "consumer: #{consumer.inspect}"
    request_token = ::OAuth::RequestToken.new(consumer, session['oauth'][name.to_s].delete('request_token'), session['oauth'][name.to_s].delete('request_secret'))
    ...
end

回調后登錄

session: {"session_id"=>"190523311f7a63fe796558691b1d4fff"}
consumer: #<OAuth::Consumer:0x103735b50 @secret="...", @http=#<Net::HTTP api.twitter.com:443 open=false>, @key="...", @options={:access_token_path=>"/oauth/access_token", :proxy=>nil, :http_method=>:post, :site=>"https://api.twitter.com", :request_token_path=>"/oauth/request_token", :scheme=>:header, :oauth_version=>"1.0", :signature_method=>"HMAC-SHA1", :authorize_path=>"/oauth/authenticate"}>

因此,從Twitter到omniauth的會話內容似乎沒有被填充或丟失。

有誰知道,什么原因會導致這種行為?

我的Gemfile:

gem 'mongrel', '1.2.0.pre2'
gem "rails", "~> 3.0.6"
gem "mysql"
gem 'omniauth'
gem 'settingslogic' # config/application.yml
gem 'will_paginate', '~> 3.0.beta'

感謝您的幫助。

在我的session_store.rb我有如下內容:

# Be sure to restart your server when you modify this file.
PersonalAccount::Application.config.session_store :cookie_store, :key => '_app_session', :secure => true

但是在我的開發環境中,我沒有使用SSL,因此OmniAuth無法存儲其會話。

刪除:secure => true解決了我的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM