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.



25
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
# File 'lib/two_step/configuration.rb', line 25

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 = "/"
  @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

#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

#find_current_resource(session, controller: nil) ⇒ Object



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

def find_current_resource(session, controller: nil)
  resolve_callable(current_resource_finder, session, controller)
end

#find_pending_resource(session, controller: nil) ⇒ Object



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

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



65
66
67
# File 'lib/two_step/configuration.rb', line 65

def (resource = nil, controller: nil)
  resolve_callable(, resource, controller)
end

#resolve_layout_body_attributes(controller: nil) ⇒ Object



85
86
87
# File 'lib/two_step/configuration.rb', line 85

def resolve_layout_body_attributes(controller: nil)
  resolve_hash(resolve_callable(layout_body_attributes, controller))
end

#resolve_layout_brand(controller: nil) ⇒ Object



89
90
91
# File 'lib/two_step/configuration.rb', line 89

def resolve_layout_brand(controller: nil)
  resolve_callable(layout_brand, controller)
end

#resolve_layout_html_attributes(controller: nil) ⇒ Object



81
82
83
# File 'lib/two_step/configuration.rb', line 81

def resolve_layout_html_attributes(controller: nil)
  resolve_hash(resolve_callable(layout_html_attributes, controller))
end

#resolve_layout_stylesheets(controller: nil) ⇒ Object



77
78
79
# File 'lib/two_step/configuration.rb', line 77

def resolve_layout_stylesheets(controller: nil)
  Array(resolve_callable(layout_stylesheets, controller)).flatten.compact
end

#resolve_layout_title(controller: nil) ⇒ Object



73
74
75
# File 'lib/two_step/configuration.rb', line 73

def resolve_layout_title(controller: nil)
  resolve_callable(layout_title, controller)
end

#resolve_login_path(controller: nil) ⇒ Object



61
62
63
# File 'lib/two_step/configuration.rb', line 61

def (controller: nil)
  resolve_callable(, controller)
end

#run_authentication_success(resource, session, controller: nil) ⇒ Object



69
70
71
# File 'lib/two_step/configuration.rb', line 69

def run_authentication_success(resource, session, controller: nil)
  resolve_callable(on_authentication_success, resource, session, controller)
end