jrallison / authlogic_oauth

Authlogic OAuth is an extension of the Authlogic library to add OAuth support. OAuth can be used to allow users to login with their Twitter credentials.
authlogic-oauth.heroku.com
MIT License
165 stars 25 forks source link

nil.params when using from console #2

Open joost opened 15 years ago

joost commented 15 years ago

I get the following error when using the User model in a environment where there is no controller. Simplest solution is to add a condition to the authenticating_with_oauth? method in acts_as_authentic.rb:

  def authenticating_with_oauth?
    if session_class.controller
      # Initial request when user presses one of the button helpers
      (session_class.controller.params && !session_class.controller.params[:register_with_oauth].blank?) ||
      # When the oauth provider responds and we made the initial request
      (oauth_response && session_class.controller.session && session_class.controller.session[:oauth_request_class] == self.class.name)
    end
  end

The error:

You have a nil object when you didn't expect it! The error occurred while evaluating nil.params /opt/local/lib/ruby/gems/1.8/gems/authlogic-oauth-1.0.8/lib/authlogic_oauth/acts_as_authentic.rb:85:in authenticating_with_oauth?' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/callbacks.rb:178:insend'

krisleech commented 15 years ago

I also get this issue, would you recommend "vendoring" the gem and applying this patch... Any chance of this patch getting applied?

joost commented 15 years ago

I think jrallison should fix this minor bug as shown above. To make it work for now you can create a file in RAILS_ROOT/lib/authlogic_oauth_hacks.rb

# Replace following in lib/authlogic_oauth.rb.
# See: http://github.com/jrallison/authlogic_oauth/issues/#issue/3
# 
#  if defined?(Authlogic) # Fixes "undefined method `acts_as_authentic_config'" error when using rake.
#    ActiveRecord::Base.send(:include, AuthlogicOauth::ActsAsAuthentic)
#    Authlogic::Session::Base.send(:include, AuthlogicOauth::Session)
#    ActionController::Base.helper AuthlogicOauth::Helper
#  end

module AuthlogicOauth
  module ActsAsAuthentic
    module Methods

      # Fixes issue. See: http://github.com/jrallison/authlogic_oauth/issues/#issue/2
      def authenticating_with_oauth?
        if session_class.controller
          # Initial request when user presses one of the button helpers
          (session_class.controller.params && !session_class.controller.params[:register_with_oauth].blank?) ||
          # When the oauth provider responds and we made the initial request
          (oauth_response && session_class.controller.session && session_class.controller.session[:oauth_request_class] == self.class.name)
        end
      end

    end
  end
radar commented 14 years ago

Quite saddened that this project has seemingly been abandoned. This is quite the critical issue and I've had to patch it myself locally. jrallison, if you're still alive: PATCH THIS. We will love you forever.

mejibyte commented 14 years ago

I just hit this bug too.

ksiomelo commented 14 years ago

me too