I'm trying to build an Application that is using the OmniAuth gem, so that Twitter users can login.
I followed the steps in the tutorials and i'm pretty sure, that i've done everything right.
But on the callback from Twitter i get this infamous error message:
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.[]
After digging deeper in the omniauth gem, i figured out, that in the OAuth#callback_phase
the session does not contain any oauth information
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
Log after callback
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"}>
开发者_运维百科
So it looks like the Session content is not filled or gets lost on the way from twitter to omniauth.
Does anyone have a idea, what can cause the behavior?
My 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'
Thanks for your help in advance.
In my session_store.rb
I had something like this:
# Be sure to restart your server when you modify this file.
PersonalAccount::Application.config.session_store :cookie_store, :key => '_app_session', :secure => true
But in my development environment I did not use SSL, so OmniAuth could not store its session.
Removing the :secure => true
resolved my problem.
精彩评论