Class: Yauth::Strategy

Inherits:
Warden::Strategies::Base
  • Object
show all
Defined in:
lib/yauth/strategy.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Strategy

Returns a new instance of Strategy.



6
7
8
9
# File 'lib/yauth/strategy.rb', line 6

def initialize(*args)
  super(*args)
  @manager = Yauth::UserManager.load(Yauth.location)
end

Instance Attribute Details

#managerObject (readonly)

Returns the value of attribute manager.



4
5
6
# File 'lib/yauth/strategy.rb', line 4

def manager
  @manager
end

Class Method Details

.install!Object



21
22
23
# File 'lib/yauth/strategy.rb', line 21

def self.install!
  Warden::Strategies.add(:yauth_users, self)
end

Instance Method Details

#authenticate!Object



11
12
13
14
15
16
17
18
19
# File 'lib/yauth/strategy.rb', line 11

def authenticate!
  auth = Rack::Auth::Basic::Request.new(env)
  credentials = auth.provided? && auth.basic? && auth.credentials 
  if not credentials or not user = manager.authenticate(*credentials)
    fail!("Could not log in") 
  else
    success!(user)
  end
end