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

authenticating_with_oauth? causes trouble when dealing with users outside of requests #11

Closed agibralter closed 14 years ago

agibralter commented 14 years ago

I need to be able to interact with my User class outside of the Rails request (e.g. in script/console or in rake tasks). When I try to save my user authenticating_with_oauth? causes an exception because session_class.controller is nil (authlogic is not activated). Perhaps authenticating_with_oauth? could be wrapped with if session_class.controller?

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)
  else
    false
  end
end
ess commented 14 years ago

@agibralter -

You might want to take a look at, and add a vote for http://github.com/jrallison/authlogic_oauth/issues#issue/2 , as it is the same issue that you've noted. As it were, it also includes a monkeypatch that you can dump in #{RAILS_ROOT}/lib and then load either in your console or your environment.rb

Granted, it appears that this issue has been fixed in a recent commit. If you're still having trouble, you might try grabbing the latest-n-greatest.

agibralter commented 14 years ago

Ah cool, thank you! I'll close this ticket now.