Module: Negroni
- Extended by:
- ActiveSupport::Autoload, Configuration::Delegation
- Defined in:
- lib/negroni.rb,
lib/negroni/engine.rb,
lib/negroni/models.rb,
lib/negroni/version.rb,
lib/negroni/omniauth.rb,
lib/negroni/resolver.rb,
lib/negroni/encryptor.rb,
lib/negroni/models/base.rb,
lib/negroni/param_filter.rb,
lib/negroni/configuration.rb,
app/mailers/negroni/mailer.rb,
lib/negroni/mailers/helpers.rb,
lib/negroni/models/lockable.rb,
lib/negroni/omniauth/config.rb,
lib/negroni/token_generator.rb,
lib/negroni/token_not_found.rb,
lib/negroni/models/recoverable.rb,
lib/negroni/models/validatable.rb,
lib/negroni/controllers/helpers.rb,
lib/negroni/models/omniauthable.rb,
lib/negroni/models/registerable.rb,
lib/negroni/models/authenticable.rb,
lib/negroni/controllers/token_authenticable.rb
Overview
Negroni extracts common authentication configuration to be used across the application.
Defined Under Namespace
Modules: Controllers, Encryptor, Mailers, Models, OmniAuth Classes: Configuration, Engine, Mailer, ParamFilter, Resolver, TokenGenerator, TokenNotFound
Constant Summary collapse
- ALL =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
To hold all modules
[]
- VERSION =
Version number
'0.1.0'
Private Configuration collapse
-
.mailer ⇒ Mailer
Returns the mailer.
-
.omniauth_configs ⇒ Hash<Symbol,OmniAuth::Config>
Stores OmniAuth configurations.
-
.paranoid ⇒ Boolean
When true, enter in paranoid mode to avoid user enumeration.
-
.secret_key ⇒ String
Stores the secret key.
-
.token_generator ⇒ TokenGenerator
Stores the token generator.
Module Registration collapse
-
.register_module(module_name, options = {}) ⇒ Void
Register available negroni modules.
Class Method Summary collapse
-
.configure {|Negroni| ... } ⇒ Void
Yields the module for configuration.
-
.friendly_token(length = 20) ⇒ String
Generate a friendly string randomly to be used as a token.
-
.omniauth(provider, *args) ⇒ Void
Register an OmniAuth provider.
-
.omniauth_providers ⇒ Array<Symbol>
List of OmniAuth provider that are registered.
-
.secure_compare(a, b) ⇒ Boolean
Securely compare two passwords.
Methods included from Configuration::Delegation
authentication_keys, case_insensitive_keys, config_delegator, configuration, email_regexp, lock_strategy, mailer_sender, maximum_attempts, not_found_exception, parent_controller, parent_mailer, password_length, pepper, reset_password_keys, reset_password_within, send_password_change_notification, stretches, strip_whitespace_keys, token_algorithm, token_audience, token_lifetime, token_public_key, token_secret, unlock_in, unlock_keys, unlock_strategy
Class Attribute Details
.omniauth_configs ⇒ Hash<Symbol,OmniAuth::Config>
Stores OmniAuth configurations
47 48 49 |
# File 'lib/negroni.rb', line 47 def omniauth_configs @omniauth_configs end |
.paranoid ⇒ Boolean
When true, enter in paranoid mode to avoid user enumeration.
51 52 53 |
# File 'lib/negroni.rb', line 51 def paranoid @paranoid end |
.secret_key ⇒ String
Stores the secret key
59 60 61 |
# File 'lib/negroni.rb', line 59 def secret_key @secret_key end |
.token_generator ⇒ TokenGenerator
Stores the token generator
55 56 57 |
# File 'lib/negroni.rb', line 55 def token_generator @token_generator end |
Class Method Details
.configure {|Negroni| ... } ⇒ Void
Yields the module for configuration. This is the standard way to configure Negroni.
82 83 84 |
# File 'lib/negroni.rb', line 82 def configure yield self end |
.friendly_token(length = 20) ⇒ String
Generate a friendly string randomly to be used as a token.
@note: Taken from ‘Devise`.
113 114 115 116 |
# File 'lib/negroni.rb', line 113 def friendly_token(length = 20) rlength = (length * 3) / 4 SecureRandom.urlsafe_base64(rlength).tr('lIO0', 'sxyz') end |
.omniauth(provider, *args) ⇒ Void
Register an OmniAuth provider.
102 103 104 105 |
# File 'lib/negroni.rb', line 102 def omniauth(provider, *args) config = Negroni::OmniAuth::Config.new(provider, args) omniauth_configs[config.strategy_name.to_sym] = config end |
.omniauth_providers ⇒ Array<Symbol>
List of OmniAuth provider that are registered
88 89 90 |
# File 'lib/negroni.rb', line 88 def omniauth_providers omniauth_configs.keys end |
.register_module(module_name, options = {}) ⇒ Void
that adding a module using this method does not cause it to be used in the authentication process. That requires that the module be listed in the arguments passed to the ‘negroni’ method in the model class definition.
Register available negroni modules. For the standard modules that Negroni provides, this method is called from lib/negroni/modules.rb. Third-party modules need to be added explicitly using this method.
All values which accept a boolean will have the same name as the given module name.
180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/negroni.rb', line 180 def register_module(module_name, = {}) .assert_valid_keys(:model, :controller, :insert_at) ALL.insert ([:insert_at] || -1), module_name if (controller = [:controller]) register_controller(controller, module_name) end [:model] && register_model([:model], module_name) end |
.secure_compare(a, b) ⇒ Boolean
Securely compare two passwords
124 125 126 127 128 129 130 131 132 |
# File 'lib/negroni.rb', line 124 def secure_compare(a, b) return false if a.blank? || b.blank? || a.bytesize != b.bytesize l = a.unpack "C#{a.bytesize}" res = 0 b.each_byte { |byte| res |= byte ^ l.shift } res.zero? end |