Class: Negroni::Configuration
- Inherits:
-
Object
- Object
- Negroni::Configuration
- Defined in:
- lib/negroni/configuration.rb
Overview
‘Configuration` encapsulates all of the configuration for Negroni, keeping it out of the main module.
Defined Under Namespace
Modules: Delegation
Constant Summary collapse
- DEFAULT_EMAIL_VALIDATION_REGEX =
The default email validation regex.
/\A[^@\s]+@[^@\s]+\z/i
Authenticable Configuration collapse
-
#authentication_keys ⇒ Array<Symbol>
Keys used when authenticating.
-
#case_insensitive_keys ⇒ Array<Symbol>
Keys that should be treated as case-insensitive.
-
#not_found_exception ⇒ Class, String
The name of the exception class that will be raised upon receiving an invalid auth token.
-
#send_password_change_notification ⇒ Boolean
When true, send an email to notify password changes.
-
#strip_whitespace_keys ⇒ Array<Symbol>
Keys that should have whitespace skipped.
-
#token_audience ⇒ Object
The audience claim to identify the recipients that the token is intended for.
-
#token_lifetime ⇒ ActiveSupport::Duration
How long before a token is expired.
Validatable Configuration collapse
-
#email_regexp ⇒ RegExp
Regular expression to validate emails.
-
#password_length ⇒ Range
Range validation for password.
Encryption Configuration collapse
-
#pepper ⇒ String
Used to hash the password.
-
#stretches ⇒ Integer
The number of times to hash the password.
-
#token_algorithm ⇒ String
The algorithm used to encode the token.
-
#token_public_key ⇒ String
An optional public key used to decode tokens.
-
#token_secret ⇒ String
The secret key that will be used for the token.
Lockable Configuration collapse
-
#lock_strategy ⇒ Symbol
Defines which strategy will be used to lock an account.
-
#maximum_attempts ⇒ Integer
Number of authentication tries before locking an account.
-
#reset_password_keys ⇒ Array<Symbol>
Defines which key will be used when recovering the password for an account.
-
#reset_password_within ⇒ ActiveSupport::Duration
Time interval you can reset your password with a reset password key.
-
#unlock_in ⇒ ActiveSupport::Duration
Time interval to unlock the account if ‘:time` is defined as `unlock_strategy`.
-
#unlock_keys ⇒ Array<Symbol>
Defines which key will be used when locking and unlocking an account.
-
#unlock_strategy ⇒ Symbol
Defines which strategy can be used to unlock an account.
Mailer Configuration collapse
-
#mailer_sender ⇒ String
The sender for all mailers.
-
#parent_mailer ⇒ String
The class ‘Mailer` should inherit from (`’ActionMailer::Base’‘ by default).
Controller Configuration collapse
-
#parent_controller ⇒ String, Class
The class ‘Negroni::BaseController` should inherit from.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
Create a new instance of ‘Configuration`, using default values for all attributes.
Constructor Details
#initialize ⇒ Configuration
Create a new instance of ‘Configuration`, using default values for all attributes.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/negroni/configuration.rb', line 147 def initialize # rubocop:disable Metrics/AbcSize,MethodLength @authentication_keys = [:email] @case_insensitive_keys = [:email] @strip_whitespace_keys = [:email] @send_password_change_notification = false @token_lifetime = 1.day @token_algorithm = 'HS256' @not_found_exception = 'Negroni::TokenNotFound' @email_regexp = DEFAULT_EMAIL_VALIDATION_REGEX @password_length = 8..72 @stretches = 11 @pepper = nil @lock_strategy = :failed_attempts @unlock_keys = [:email] @unlock_strategy = :both @maximum_attempts = 20 @unlock_in = 1.hour @reset_password_keys = [:email] @reset_password_within = 6.hours @mailer_sender = nil @parent_mailer = 'ActionMailer::Base' @parent_controller = 'ActionController::API' end |
Instance Attribute Details
#authentication_keys ⇒ Array<Symbol>
Keys used when authenticating
15 16 17 |
# File 'lib/negroni/configuration.rb', line 15 def authentication_keys @authentication_keys end |
#case_insensitive_keys ⇒ Array<Symbol>
Keys that should be treated as case-insensitive
19 20 21 |
# File 'lib/negroni/configuration.rb', line 19 def case_insensitive_keys @case_insensitive_keys end |
#email_regexp ⇒ RegExp
Regular expression to validate emails
53 54 55 |
# File 'lib/negroni/configuration.rb', line 53 def email_regexp @email_regexp end |
#lock_strategy ⇒ Symbol
Defines which strategy will be used to lock an account.
* `:failed_attempts` = Locks an account after a number of failed
attempts.
* `:none` = No lock strategy. You should handle locking by
yourself.
95 96 97 |
# File 'lib/negroni/configuration.rb', line 95 def lock_strategy @lock_strategy end |
#mailer_sender ⇒ String
The sender for all mailers
128 129 130 |
# File 'lib/negroni/configuration.rb', line 128 def mailer_sender @mailer_sender end |
#maximum_attempts ⇒ Integer
Number of authentication tries before locking an account
108 109 110 |
# File 'lib/negroni/configuration.rb', line 108 def maximum_attempts @maximum_attempts end |
#not_found_exception ⇒ Class, String
The name of the exception class that will be raised upon receiving an invalid auth token.
Default: TokenNotFound
47 48 49 |
# File 'lib/negroni/configuration.rb', line 47 def not_found_exception @not_found_exception end |
#parent_controller ⇒ String, Class
The class ‘Negroni::BaseController` should inherit from.
Default: ActionController::API
141 142 143 |
# File 'lib/negroni/configuration.rb', line 141 def parent_controller @parent_controller end |
#parent_mailer ⇒ String
The class ‘Mailer` should inherit from (`’ActionMailer::Base’‘ by default)
132 133 134 |
# File 'lib/negroni/configuration.rb', line 132 def parent_mailer @parent_mailer end |
#password_length ⇒ Range
Range validation for password
57 58 59 |
# File 'lib/negroni/configuration.rb', line 57 def password_length @password_length end |
#pepper ⇒ String
Used to hash the password. Generate one with ‘rake secret`.
67 68 69 |
# File 'lib/negroni/configuration.rb', line 67 def pepper @pepper end |
#reset_password_keys ⇒ Array<Symbol>
Defines which key will be used when recovering the password for an account
118 119 120 |
# File 'lib/negroni/configuration.rb', line 118 def reset_password_keys @reset_password_keys end |
#reset_password_within ⇒ ActiveSupport::Duration
Time interval you can reset your password with a reset password key
122 123 124 |
# File 'lib/negroni/configuration.rb', line 122 def reset_password_within @reset_password_within end |
#send_password_change_notification ⇒ Boolean
When true, send an email to notify password changes
27 28 29 |
# File 'lib/negroni/configuration.rb', line 27 def send_password_change_notification @send_password_change_notification end |
#stretches ⇒ Integer
The number of times to hash the password
63 64 65 |
# File 'lib/negroni/configuration.rb', line 63 def stretches @stretches end |
#strip_whitespace_keys ⇒ Array<Symbol>
Keys that should have whitespace skipped
23 24 25 |
# File 'lib/negroni/configuration.rb', line 23 def strip_whitespace_keys @strip_whitespace_keys end |
#token_algorithm ⇒ String
The algorithm used to encode the token. Default: ‘HS256’
72 73 74 |
# File 'lib/negroni/configuration.rb', line 72 def token_algorithm @token_algorithm end |
#token_audience ⇒ Object
The audience claim to identify the recipients that the token is intended for.
39 40 41 |
# File 'lib/negroni/configuration.rb', line 39 def token_audience @token_audience end |
#token_lifetime ⇒ ActiveSupport::Duration
How long before a token is expired. If nil is provided, token will last forever.
33 34 35 |
# File 'lib/negroni/configuration.rb', line 33 def token_lifetime @token_lifetime end |
#token_public_key ⇒ String
An optional public key used to decode tokens.
83 84 85 |
# File 'lib/negroni/configuration.rb', line 83 def token_public_key @token_public_key end |
#token_secret ⇒ String
The secret key that will be used for the token. Default: secret_key.
78 79 80 |
# File 'lib/negroni/configuration.rb', line 78 def token_secret @token_secret end |
#unlock_in ⇒ ActiveSupport::Duration
Time interval to unlock the account if ‘:time` is defined as `unlock_strategy`.
114 115 116 |
# File 'lib/negroni/configuration.rb', line 114 def unlock_in @unlock_in end |
#unlock_keys ⇒ Array<Symbol>
Defines which key will be used when locking and unlocking an account
99 100 101 |
# File 'lib/negroni/configuration.rb', line 99 def unlock_keys @unlock_keys end |
#unlock_strategy ⇒ Symbol
Defines which strategy can be used to unlock an account. Valid values: ‘:email,` `:time,` `:both`
104 105 106 |
# File 'lib/negroni/configuration.rb', line 104 def unlock_strategy @unlock_strategy end |