Class: TwoStep::Configuration
- Inherits:
-
Object
- Object
- TwoStep::Configuration
- Defined in:
- lib/two_step/configuration.rb
Instance Attribute Summary collapse
-
#after_two_step_login_path ⇒ Object
Returns the value of attribute after_two_step_login_path.
-
#backup_code_count ⇒ Object
Returns the value of attribute backup_code_count.
-
#backup_code_digest_method ⇒ Object
Returns the value of attribute backup_code_digest_method.
-
#backup_code_verify_method ⇒ Object
Returns the value of attribute backup_code_verify_method.
-
#challenge_skip_allowed ⇒ Object
Returns the value of attribute challenge_skip_allowed.
-
#current_resource_finder ⇒ Object
Returns the value of attribute current_resource_finder.
-
#issuer ⇒ Object
Returns the value of attribute issuer.
-
#layout_body_attributes ⇒ Object
Returns the value of attribute layout_body_attributes.
-
#layout_brand ⇒ Object
Returns the value of attribute layout_brand.
-
#layout_html_attributes ⇒ Object
Returns the value of attribute layout_html_attributes.
-
#layout_stylesheets ⇒ Object
Returns the value of attribute layout_stylesheets.
-
#layout_title ⇒ Object
Returns the value of attribute layout_title.
-
#login_path ⇒ Object
Returns the value of attribute login_path.
-
#on_authentication_success ⇒ Object
Returns the value of attribute on_authentication_success.
-
#otp_drift_ahead ⇒ Object
Returns the value of attribute otp_drift_ahead.
-
#otp_drift_behind ⇒ Object
Returns the value of attribute otp_drift_behind.
-
#qr_code_module_size ⇒ Object
Returns the value of attribute qr_code_module_size.
-
#resource_finder ⇒ Object
Returns the value of attribute resource_finder.
Instance Method Summary collapse
- #challenge_skip_allowed_for?(resource = nil, controller: nil) ⇒ Boolean
- #find_current_resource(session, controller: nil) ⇒ Object
- #find_pending_resource(session, controller: nil) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #resolve_after_two_step_login_path(resource = nil, controller: nil) ⇒ Object
- #resolve_layout_body_attributes(controller: nil) ⇒ Object
- #resolve_layout_brand(controller: nil) ⇒ Object
- #resolve_layout_html_attributes(controller: nil) ⇒ Object
- #resolve_layout_stylesheets(controller: nil) ⇒ Object
- #resolve_layout_title(controller: nil) ⇒ Object
- #resolve_login_path(controller: nil) ⇒ Object
- #run_authentication_success(resource, session, controller: nil) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/two_step/configuration.rb', line 26 def initialize @issuer = "Rails App" @backup_code_count = 10 @qr_code_module_size = 4 @otp_drift_behind = 30 @otp_drift_ahead = 30 @resource_finder = ->(*) {} @current_resource_finder = ->(*) {} @login_path = "/" @after_two_step_login_path = "/" @challenge_skip_allowed = ->(*) { false } @on_authentication_success = ->(*) {} @layout_title = -> { "#{issuer} Security" } @layout_stylesheets = ["two_step/application"] @layout_html_attributes = -> { {lang: I18n.locale} } @layout_body_attributes = {class: "two_step-shell"} @layout_brand = -> { issuer } # Switched to SHA256 for O(1) performance during generation. # Because the backup codes are 15 characters of high-entropy randomness, # a slow-hash like BCrypt is unnecessary and harms user experience. @backup_code_digest_method = ->(normalized_code) { Digest::SHA256.hexdigest(normalized_code) } @backup_code_verify_method = ->(normalized_code, hashed) { Rack::Utils.secure_compare(Digest::SHA256.hexdigest(normalized_code), hashed) } end |
Instance Attribute Details
#after_two_step_login_path ⇒ Object
Returns the value of attribute after_two_step_login_path.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def after_two_step_login_path @after_two_step_login_path end |
#backup_code_count ⇒ Object
Returns the value of attribute backup_code_count.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def backup_code_count @backup_code_count end |
#backup_code_digest_method ⇒ Object
Returns the value of attribute backup_code_digest_method.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def backup_code_digest_method @backup_code_digest_method end |
#backup_code_verify_method ⇒ Object
Returns the value of attribute backup_code_verify_method.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def backup_code_verify_method @backup_code_verify_method end |
#challenge_skip_allowed ⇒ Object
Returns the value of attribute challenge_skip_allowed.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def challenge_skip_allowed @challenge_skip_allowed end |
#current_resource_finder ⇒ Object
Returns the value of attribute current_resource_finder.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def current_resource_finder @current_resource_finder end |
#issuer ⇒ Object
Returns the value of attribute issuer.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def issuer @issuer end |
#layout_body_attributes ⇒ Object
Returns the value of attribute layout_body_attributes.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def layout_body_attributes @layout_body_attributes end |
#layout_brand ⇒ Object
Returns the value of attribute layout_brand.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def layout_brand @layout_brand end |
#layout_html_attributes ⇒ Object
Returns the value of attribute layout_html_attributes.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def layout_html_attributes @layout_html_attributes end |
#layout_stylesheets ⇒ Object
Returns the value of attribute layout_stylesheets.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def layout_stylesheets @layout_stylesheets end |
#layout_title ⇒ Object
Returns the value of attribute layout_title.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def layout_title @layout_title end |
#login_path ⇒ Object
Returns the value of attribute login_path.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def login_path @login_path end |
#on_authentication_success ⇒ Object
Returns the value of attribute on_authentication_success.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def on_authentication_success @on_authentication_success end |
#otp_drift_ahead ⇒ Object
Returns the value of attribute otp_drift_ahead.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def otp_drift_ahead @otp_drift_ahead end |
#otp_drift_behind ⇒ Object
Returns the value of attribute otp_drift_behind.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def otp_drift_behind @otp_drift_behind end |
#qr_code_module_size ⇒ Object
Returns the value of attribute qr_code_module_size.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def qr_code_module_size @qr_code_module_size end |
#resource_finder ⇒ Object
Returns the value of attribute resource_finder.
7 8 9 |
# File 'lib/two_step/configuration.rb', line 7 def resource_finder @resource_finder end |
Instance Method Details
#challenge_skip_allowed_for?(resource = nil, controller: nil) ⇒ Boolean
71 72 73 |
# File 'lib/two_step/configuration.rb', line 71 def challenge_skip_allowed_for?(resource = nil, controller: nil) !!resolve_callable(challenge_skip_allowed, resource, controller) end |
#find_current_resource(session, controller: nil) ⇒ Object
59 60 61 |
# File 'lib/two_step/configuration.rb', line 59 def find_current_resource(session, controller: nil) resolve_callable(current_resource_finder, session, controller) end |
#find_pending_resource(session, controller: nil) ⇒ Object
55 56 57 |
# File 'lib/two_step/configuration.rb', line 55 def find_pending_resource(session, controller: nil) resolve_callable(resource_finder, session, controller) end |
#resolve_after_two_step_login_path(resource = nil, controller: nil) ⇒ Object
67 68 69 |
# File 'lib/two_step/configuration.rb', line 67 def resolve_after_two_step_login_path(resource = nil, controller: nil) resolve_callable(after_two_step_login_path, resource, controller) end |
#resolve_layout_body_attributes(controller: nil) ⇒ Object
91 92 93 |
# File 'lib/two_step/configuration.rb', line 91 def resolve_layout_body_attributes(controller: nil) resolve_hash(resolve_callable(layout_body_attributes, controller)) end |
#resolve_layout_brand(controller: nil) ⇒ Object
95 96 97 |
# File 'lib/two_step/configuration.rb', line 95 def resolve_layout_brand(controller: nil) resolve_callable(layout_brand, controller) end |
#resolve_layout_html_attributes(controller: nil) ⇒ Object
87 88 89 |
# File 'lib/two_step/configuration.rb', line 87 def resolve_layout_html_attributes(controller: nil) resolve_hash(resolve_callable(layout_html_attributes, controller)) end |
#resolve_layout_stylesheets(controller: nil) ⇒ Object
83 84 85 |
# File 'lib/two_step/configuration.rb', line 83 def resolve_layout_stylesheets(controller: nil) Array(resolve_callable(layout_stylesheets, controller)).flatten.compact end |
#resolve_layout_title(controller: nil) ⇒ Object
79 80 81 |
# File 'lib/two_step/configuration.rb', line 79 def resolve_layout_title(controller: nil) resolve_callable(layout_title, controller) end |
#resolve_login_path(controller: nil) ⇒ Object
63 64 65 |
# File 'lib/two_step/configuration.rb', line 63 def resolve_login_path(controller: nil) resolve_callable(login_path, controller) end |
#run_authentication_success(resource, session, controller: nil) ⇒ Object
75 76 77 |
# File 'lib/two_step/configuration.rb', line 75 def run_authentication_success(resource, session, controller: nil) resolve_callable(on_authentication_success, resource, session, controller) end |