Module: Rack::Webauth::WardenStrategy::InstanceMethods

Includes:
Helpers
Included in:
Rack::Webauth::WardenStrategy
Defined in:
lib/rack-webauth/warden_strategy.rb

Overview

Actual functionality of WardenStrategy, so it can be used within other classes as well, without the need to inherit from Warden::Strategies::Base.

Especially useful when using devise:

class MyWebauthStrategy < Devise::Strategies::Authenticatable
  include Rack::Webauth::WardenStrategy::InstanceMethods

  self.finder = lambda {
    mapping.to.find_by_email(webauth.attributes['mail'])
  }
end

For more information about Devise see github.com/plataformatec/devise

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


39
40
41
# File 'lib/rack-webauth/warden_strategy.rb', line 39

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#authenticate!Object


49
50
51
52
53
54
55
# File 'lib/rack-webauth/warden_strategy.rb', line 49

def authenticate!
  if user = instance_eval(&self.class.finder)
    success!(user)
  else
    fail!(:invalid)
  end
end

#valid?Boolean

Returns:

  • (Boolean)

45
46
47
# File 'lib/rack-webauth/warden_strategy.rb', line 45

def valid?
  webauth.logged_in?
end