Module: Devise::Models::TwoFactorAuthenticatable::ClassMethods

Defined in:
lib/devise_multi_factor/models/two_factor_authenticatable.rb

Instance Method Summary collapse

Instance Method Details

#generate_totp_secretObject



21
22
23
24
25
26
# File 'lib/devise_multi_factor/models/two_factor_authenticatable.rb', line 21

def generate_totp_secret
  # ROTP gem since version 5 to version 5.1
  # at version 5.1 ROTP gem reinstates.
  # Details: https://github.com/mdp/rotp/blob/master/CHANGELOG.md#510
  ROTP::Base32.try(:random) || ROTP::Base32.random_base32
end

#has_one_time_password(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/devise_multi_factor/models/two_factor_authenticatable.rb', line 10

def has_one_time_password(options = {})
  include InstanceMethodsOnActivation

  encrypt_options = {
    key: otp_secret_encryption_key,
    encrypted_attribute: 'encrypted_otp_secret_key',
  }.compact
  encrypt_options = encrypt_options.merge(options[:encrypt]) if options[:encrypt].is_a?(Hash)
  has_encrypted(:otp_secret_key, **(encrypt_options || {}))
end