Class: IAuthU::Authenticator::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/iauthu/authenticator/base.rb

Overview

IAuthU uses ‘Authentication’ objects to validate and authenticate users.

Any object can be used for authentication as long as it follows the following
conventions:
- has a #call method that accepts a username and password
- the #call method returns an identity hash in the form:
    { :username => 'john.doe',
      :display_name => 'John Doe',
      :email => '[email protected]',
      :identifier => '',
      :credentials => [:admin, :user] }
- the identity hash MUST contain a :username entry
- if authentication fails the #call method should return nil

This convention allows the use of lambda objects as authenticators:
    lambda {|user,pass| 
      if user == 'foo'
        {:username => user, :credentials => [:admin]}
      end 
    }

There are also optional behavior methods that authentication objects 
should, but are not required to implement:
#required::     specifies that an authentication object is required. In an
                authentication chain, failure of authenticator objects that are required
                causes the entire chain to fail.
#sufficient::   specifies that an authentication object is sufficient for
                authentication. In an auth chain, authenticator objects that are sufficient
                and successfully authenticate halt the execution of the chain and cause the
                chain to return a successful authentication.

If you require custom authentication, subclass IAuthU::Authenticator::Base
and override #call to perform your custom authentication. You may also use
any object that implements #call as specified above. If you require multiple
authentication steps, you may compose authenticators together using 
IAuthU::Authenticator::Chained.

Direct Known Subclasses

Chained

Instance Method Summary collapse

Instance Method Details

#call(username, password) ⇒ Object



42
43
44
# File 'lib/iauthu/authenticator/base.rb', line 42

def call(username, password)
  nil
end

#requiredObject



46
47
48
# File 'lib/iauthu/authenticator/base.rb', line 46

def required
  @required ||= false
end

#required=(bool) ⇒ Object



50
51
52
# File 'lib/iauthu/authenticator/base.rb', line 50

def required=(bool)
  @required = !!bool
end

#sufficientObject



54
55
56
# File 'lib/iauthu/authenticator/base.rb', line 54

def sufficient
  @sufficient ||= false
end

#sufficient=(bool) ⇒ Object



58
59
60
# File 'lib/iauthu/authenticator/base.rb', line 58

def sufficient=(bool)
  @sufficient = !!bool
end