Module: Oath

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

Overview

Oath is an authentication toolkit designed to allow developers to create their own authentication solutions. If you're interested in a default implementation try Oath 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.0

Since:

  • 0.0.15

"1.1.0"

Class Method Summary collapse

Class Method Details

.compare_token(digest, token) ⇒ Boolean

compares the token (undigested password) to a digested password


45
46
47
# File 'lib/oath.rb', line 45

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

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

Configures oath

Examples:

A custom configuration

Oath.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


112
113
114
115
# File 'lib/oath.rb', line 112

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

.hash_token(token) ⇒ String

hashes a token


54
55
56
# File 'lib/oath.rb', line 54

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 Oath

initialize Oath. Sets up warden and the default configuration.

See Also:

Since:

  • 0.0.15


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

def self.initialize warden_config
  setup_config
  setup_warden_config(warden_config)
end

.lookup(params, field_map) ⇒ User?

finds a user based on their credentials

See Also:

Since:

  • 0.0.15


86
87
88
89
90
91
# File 'lib/oath.rb', line 86

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 oath in your tests

Puts oath into test mode. This will disable hashing passwords

Since:

  • 0.0.15


95
96
97
98
99
100
101
102
# File 'lib/oath.rb', line 95

def self.test_mode!
  Warden.test_mode!
  self.config ||= Oath::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 oath in between tests.

Since:

  • 0.0.15


119
120
121
# File 'lib/oath.rb', line 119

def self.test_reset!
  Warden.test_reset!
end

.transform_params(params) ⇒ Hash

performs transformations on params for signing up and signing in

See Also:

  • Oath::Configuration#param_transofmrations

Since:

  • 0.0.15


64
65
66
# File 'lib/oath.rb', line 64

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

.user_classClass

Deprecated.

Use Oath.config.user_class instead

the user class

See Also:

  • Oath::Configuration#setup_class_defaults

Since:

  • 0.0.15


73
74
75
76
77
# File 'lib/oath.rb', line 73

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