Module: Monban

Defined in:
lib/monban.rb,
lib/monban/railtie.rb,
lib/monban/version.rb,
lib/monban/back_door.rb,
lib/monban/field_map.rb,
lib/monban/failure_app.rb,
lib/monban/test/helpers.rb,
lib/monban/warden_setup.rb,
lib/monban/configuration.rb,
lib/monban/services/sign_in.rb,
lib/monban/services/sign_up.rb,
lib/monban/param_transformer.rb,
lib/monban/services/sign_out.rb,
lib/monban/controller_helpers.rb,
lib/monban/constraints/signed_in.rb,
lib/monban/constraints/signed_out.rb,
lib/monban/services/authentication.rb,
lib/monban/services/password_reset.rb,
lib/monban/test/controller_helpers.rb,
lib/monban/strategies/password_strategy.rb

Overview

Monban is an authentication toolkit designed to allow developers to create their own authentication solutions. If you’re interested in a default implementation try Monban Generators

Since:

  • 0.0.15

Defined Under Namespace

Modules: Constraints, ControllerHelpers, Services, Strategies, Test Classes: BackDoor, Configuration, FailureApp, FieldMap, ParamTransformer, Railtie, WardenSetup

Constant Summary collapse

VERSION =

1.1.1

Since:

  • 0.0.15

"1.1.1"

Class Method Summary collapse

Class Method Details

.compare_token(digest, token) ⇒ Boolean

compares the token (undigested password) to a digested password

Parameters:

  • digest (String)

    A digested password

  • token (String)

    An undigested password

Returns:

  • (Boolean)

    whether the token and digest match

See Also:

Since:

  • 0.0.15



46
47
48
# File 'lib/monban.rb', line 46

def self.compare_token(digest, token)
  config.token_comparison.call(digest, token)
end

.configure {|configuration| ... } ⇒ Object

Configures monban

Examples:

A custom configuration

Monban.configure do |config|
  config.user_lookup_field = :username
  config.user_token_store_field = :hashed_password
end

Yields:

  • (configuration)

    Yield the current configuration

Since:

  • 0.0.15



114
115
116
117
# File 'lib/monban.rb', line 114

def self.configure(&block)
  self.config ||= Monban::Configuration.new
  yield self.config
end

.hash_token(token) ⇒ String

hashes a token

Parameters:

  • token (String)

    the password in undigested form

Returns:

  • (String)

    a digest of the token

See Also:

Since:

  • 0.0.15



55
56
57
# File 'lib/monban.rb', line 55

def self.hash_token(token)
  config.hashing_method.call(token)
end

.initialize(warden_config) ⇒ Object

Note:

This is used in Railtie in order to bootstrap Monban

initialize Monban. Sets up warden and the default configuration.

Parameters:

  • warden_config (Warden::Config)

    the configuration from warden

See Also:

Since:

  • 0.0.15



34
35
36
37
38
# File 'lib/monban.rb', line 34

def self.initialize warden_config
  warn "[DEPRECATION] Monban has been renamed to oath, please update your Gemfile"
  setup_config
  setup_warden_config(warden_config)
end

.lookup(params, field_map) ⇒ User?

finds a user based on their credentials

Parameters:

  • params (Hash)

    a hash of user parameters

  • field_map (FieldMap)

    a field map in order to allow multiple lookup fields

Returns:

  • (User)

    if user is found

  • (nil)

    if no user is found

See Also:

Since:

  • 0.0.15



88
89
90
91
92
93
# File 'lib/monban.rb', line 88

def self.lookup(params, field_map)
  if params.present?
    fields = FieldMap.new(params, field_map).to_fields
    self.config.find_method.call(fields)
  end
end

.test_mode!Object

Note:

You must call this if you want to use monban in your tests

Puts monban into test mode. This will disable hashing passwords

Since:

  • 0.0.15



97
98
99
100
101
102
103
104
# File 'lib/monban.rb', line 97

def self.test_mode!
  Warden.test_mode!
  self.config ||= Monban::Configuration.new
  config.hashing_method = ->(password) { password }
  config.token_comparison = ->(digest, undigested_password) do
    digest == undigested_password
  end
end

.test_reset!Object

Note:

You must call this between tests

Resets monban in between tests.

Since:

  • 0.0.15



121
122
123
# File 'lib/monban.rb', line 121

def self.test_reset!
  Warden.test_reset!
end

.transform_params(params) ⇒ Hash

performs transformations on params for signing up and signing in

Parameters:

  • params (Hash)

    hash of parameters to transform

Returns:

  • (Hash)

    hash with transformed parameters

See Also:

  • Monban::Configuration#param_transofmrations

Since:

  • 0.0.15



66
67
68
# File 'lib/monban.rb', line 66

def self.transform_params(params)
  ParamTransformer.new(params, config.param_transformations).to_h
end

.user_classClass

Deprecated.

Use Monban.config.user_class instead

the user class

Returns:

  • (Class)

    the User class

See Also:

  • Monban::Configuration#setup_class_defaults

Since:

  • 0.0.15



75
76
77
78
79
# File 'lib/monban.rb', line 75

def self.user_class
  warn "#{Kernel.caller.first}: [DEPRECATION] " +
    'Accessing the user class through the Monban module is deprecated. Use Monban.config.user_class instead.'
  config.user_class
end