Class: Negroni::Configuration

Inherits:
Object
  • Object
show all
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

Validatable Configuration collapse

Encryption Configuration collapse

Lockable Configuration collapse

Mailer Configuration collapse

Controller Configuration collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_keysArray<Symbol>

Keys used when authenticating

Returns:

  • (Array<Symbol>)


15
16
17
# File 'lib/negroni/configuration.rb', line 15

def authentication_keys
  @authentication_keys
end

#case_insensitive_keysArray<Symbol>

Keys that should be treated as case-insensitive

Returns:

  • (Array<Symbol>)


19
20
21
# File 'lib/negroni/configuration.rb', line 19

def case_insensitive_keys
  @case_insensitive_keys
end

#email_regexpRegExp

Regular expression to validate emails

Returns:

  • (RegExp)


53
54
55
# File 'lib/negroni/configuration.rb', line 53

def email_regexp
  @email_regexp
end

#lock_strategySymbol

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.

Returns:

  • (Symbol)

    the name of the lock strategy.



95
96
97
# File 'lib/negroni/configuration.rb', line 95

def lock_strategy
  @lock_strategy
end

#mailer_senderString

The sender for all mailers

Returns:

  • (String)

    the email address for the sender



128
129
130
# File 'lib/negroni/configuration.rb', line 128

def mailer_sender
  @mailer_sender
end

#maximum_attemptsInteger

Number of authentication tries before locking an account

Returns:

  • (Integer)


108
109
110
# File 'lib/negroni/configuration.rb', line 108

def maximum_attempts
  @maximum_attempts
end

#not_found_exceptionClass, String

The name of the exception class that will be raised upon receiving an invalid auth token.

Default: TokenNotFound

Returns:

  • (Class, String)


47
48
49
# File 'lib/negroni/configuration.rb', line 47

def not_found_exception
  @not_found_exception
end

#parent_controllerString, Class

The class ‘Negroni::BaseController` should inherit from.

Default: ActionController::API

Returns:

  • (String, Class)


141
142
143
# File 'lib/negroni/configuration.rb', line 141

def parent_controller
  @parent_controller
end

#parent_mailerString

The class ‘Mailer` should inherit from (`’ActionMailer::Base’‘ by default)

Returns:

  • (String)


132
133
134
# File 'lib/negroni/configuration.rb', line 132

def parent_mailer
  @parent_mailer
end

#password_lengthRange

Range validation for password

Returns:

  • (Range)


57
58
59
# File 'lib/negroni/configuration.rb', line 57

def password_length
  @password_length
end

#pepperString

Used to hash the password. Generate one with ‘rake secret`.

Returns:

  • (String)

    the pepper used to hash the password



67
68
69
# File 'lib/negroni/configuration.rb', line 67

def pepper
  @pepper
end

#reset_password_keysArray<Symbol>

Defines which key will be used when recovering the password for an account

Returns:

  • (Array<Symbol>)


118
119
120
# File 'lib/negroni/configuration.rb', line 118

def reset_password_keys
  @reset_password_keys
end

#reset_password_withinActiveSupport::Duration

Time interval you can reset your password with a reset password key

Returns:

  • (ActiveSupport::Duration)


122
123
124
# File 'lib/negroni/configuration.rb', line 122

def reset_password_within
  @reset_password_within
end

#send_password_change_notificationBoolean

When true, send an email to notify password changes

Returns:

  • (Boolean)


27
28
29
# File 'lib/negroni/configuration.rb', line 27

def send_password_change_notification
  @send_password_change_notification
end

#stretchesInteger

The number of times to hash the password

Returns:

  • (Integer)


63
64
65
# File 'lib/negroni/configuration.rb', line 63

def stretches
  @stretches
end

#strip_whitespace_keysArray<Symbol>

Keys that should have whitespace skipped

Returns:

  • (Array<Symbol>)


23
24
25
# File 'lib/negroni/configuration.rb', line 23

def strip_whitespace_keys
  @strip_whitespace_keys
end

#token_algorithmString

The algorithm used to encode the token. Default: ‘HS256’

Returns:

  • (String)


72
73
74
# File 'lib/negroni/configuration.rb', line 72

def token_algorithm
  @token_algorithm
end

#token_audienceObject

The audience claim to identify the recipients that the token is intended for.

Returns:

  • (Object)


39
40
41
# File 'lib/negroni/configuration.rb', line 39

def token_audience
  @token_audience
end

#token_lifetimeActiveSupport::Duration

How long before a token is expired. If nil is provided, token will last forever.

Returns:

  • (ActiveSupport::Duration)


33
34
35
# File 'lib/negroni/configuration.rb', line 33

def token_lifetime
  @token_lifetime
end

#token_public_keyString

An optional public key used to decode tokens.

Returns:

  • (String)


83
84
85
# File 'lib/negroni/configuration.rb', line 83

def token_public_key
  @token_public_key
end

#token_secretString

The secret key that will be used for the token. Default: secret_key.

Returns:

  • (String)


78
79
80
# File 'lib/negroni/configuration.rb', line 78

def token_secret
  @token_secret
end

#unlock_inActiveSupport::Duration

Time interval to unlock the account if ‘:time` is defined as `unlock_strategy`.

Returns:

  • (ActiveSupport::Duration)


114
115
116
# File 'lib/negroni/configuration.rb', line 114

def unlock_in
  @unlock_in
end

#unlock_keysArray<Symbol>

Defines which key will be used when locking and unlocking an account

Returns:

  • (Array<Symbol>)


99
100
101
# File 'lib/negroni/configuration.rb', line 99

def unlock_keys
  @unlock_keys
end

#unlock_strategySymbol

Defines which strategy can be used to unlock an account. Valid values: ‘:email,` `:time,` `:both`

Returns:

  • (Symbol)


104
105
106
# File 'lib/negroni/configuration.rb', line 104

def unlock_strategy
  @unlock_strategy
end