Class: TwoStep::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/two_step/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_pathObject

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
end

#backup_code_countObject

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_methodObject

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_methodObject

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_allowedObject

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_finderObject

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

#issuerObject

Returns the value of attribute issuer.



7
8
9
# File 'lib/two_step/configuration.rb', line 7

def issuer
  @issuer
end

#layout_body_attributesObject

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_brandObject

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_attributesObject

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_stylesheetsObject

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_titleObject

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_pathObject

Returns the value of attribute login_path.



7
8
9
# File 'lib/two_step/configuration.rb', line 7

def 
  @login_path
end

#on_authentication_successObject

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_aheadObject

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_behindObject

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_sizeObject

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_finderObject

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

Returns:

  • (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 (resource = nil, controller: nil)
  resolve_callable(, 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 (controller: nil)
  resolve_callable(, 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