Module: Devise::Models::TwoFactorAuthenticatable
- Extended by:
- ActiveSupport::Concern
- Includes:
- DatabaseAuthenticatable
- Defined in:
- lib/devise_two_factor/models/two_factor_authenticatable.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #clean_up_passwords ⇒ Object
- #current_otp ⇒ Object
- #otp(otp_secret = self.otp_secret) ⇒ Object
- #otp_provisioning_uri(account, options = {}) ⇒ Object
-
#valid_otp?(code, options = {}) ⇒ Boolean
This defaults to the model’s otp_secret If this hasn’t been generated yet, pass a secret as an option.
Class Method Details
.required_fields(klass) ⇒ Object
18 19 20 |
# File 'lib/devise_two_factor/models/two_factor_authenticatable.rb', line 18 def self.required_fields(klass) [:encrypted_otp_secret, :encrypted_otp_secret_iv, :encrypted_otp_secret_salt] end |
Instance Method Details
#clean_up_passwords ⇒ Object
45 46 47 |
# File 'lib/devise_two_factor/models/two_factor_authenticatable.rb', line 45 def clean_up_passwords self.otp_attempt = nil end |
#current_otp ⇒ Object
36 37 38 |
# File 'lib/devise_two_factor/models/two_factor_authenticatable.rb', line 36 def current_otp otp.at(Time.now) end |
#otp(otp_secret = self.otp_secret) ⇒ Object
32 33 34 |
# File 'lib/devise_two_factor/models/two_factor_authenticatable.rb', line 32 def otp(otp_secret = self.otp_secret) ROTP::TOTP.new(otp_secret) end |
#otp_provisioning_uri(account, options = {}) ⇒ Object
40 41 42 43 |
# File 'lib/devise_two_factor/models/two_factor_authenticatable.rb', line 40 def otp_provisioning_uri(account, = {}) otp_secret = [:otp_secret] || self.otp_secret ROTP::TOTP.new(otp_secret, ).provisioning_uri(account) end |
#valid_otp?(code, options = {}) ⇒ Boolean
This defaults to the model’s otp_secret If this hasn’t been generated yet, pass a secret as an option
24 25 26 27 28 29 30 |
# File 'lib/devise_two_factor/models/two_factor_authenticatable.rb', line 24 def valid_otp?(code, = {}) otp_secret = [:otp_secret] || self.otp_secret return false unless otp_secret.present? totp = self.otp(otp_secret) totp.verify_with_drift(code, self.class.otp_allowed_drift) end |