Class: Aker::Modes::Base

Inherits:
Warden::Strategies::Base
  • Object
show all
Includes:
Rack::EnvironmentHelper
Defined in:
lib/aker/modes/base.rb

Overview

Base class for all authentication modes.

An authentication mode is an an object that implements an authentication protocol. Modes may be interactive, meaning that they require input from a human, and/or non-interactive, meaning that they can be used without user intervention.

For mode implementors: While it is not strictly necessary to implement aker modes as subclasses of Aker::Modes::Base, it is recommended that you do so.

Author:

  • David Yip

Instance Method Summary collapse

Instance Method Details

#authenticate!

This method returns an undefined value.

Authenticates a user.

#authenticate! expects kind and credentials to be defined. See subclasses for examples.

If authentication is successful, then success! (from Warden::Strategies::Base) is called with a User object. If authentication fails, then nothing is done.


79
80
81
82
# File 'lib/aker/modes/base.rb', line 79

def authenticate!
  user = authority.valid_credentials?(kind, *credentials)
  success!(user) if user
end

#authorityObject

Exposes the authority this mode will use to validate credentials. Internally it is extracted from the aker.authority Rack environment variable.


36
37
38
# File 'lib/aker/modes/base.rb', line 36

def authority
  super(env)
end

#configurationAker::Configuration

Exposes the configuration this mode should use.


26
27
28
# File 'lib/aker/modes/base.rb', line 26

def configuration
  super(env)
end

#interactive?Boolean

Whether or not the current request is interactive.


44
45
46
# File 'lib/aker/modes/base.rb', line 44

def interactive?
  super(env)
end

#store?Boolean

Used by Warden to determine whether or not it should store user information in the session. In Aker, this is computed as the result of #interactive?.

N.B. The !! is present because Warden requires that this method return false (not false or nil) for session serialization to be disabled.


64
65
66
# File 'lib/aker/modes/base.rb', line 64

def store?
  !!interactive?
end