Browse Source

Merge fc88ef7ed6 into 5fa6ba40d9

pull/2/merge
Recker Swartz 3 years ago committed by GitHub
parent
commit
7cf6589b4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      lib/two_factor_authentication.rb
  2. 14
      lib/two_factor_authentication/models/two_factor_authenticatable.rb

6
lib/two_factor_authentication.rb

@ -32,6 +32,12 @@ module Devise
mattr_accessor :delete_cookie_on_logout mattr_accessor :delete_cookie_on_logout
@@delete_cookie_on_logout = false @@delete_cookie_on_logout = false
mattr_accessor :issuer_name
@@issuer = ''
mattr_accessor :logo_url
@@logo_url = ''
end end
module TwoFactorAuthentication module TwoFactorAuthentication

14
lib/two_factor_authentication/models/two_factor_authenticatable.rb

@ -16,7 +16,8 @@ module Devise
::Devise::Models.config( ::Devise::Models.config(
self, :max_login_attempts, :allowed_otp_drift_seconds, :otp_length, self, :max_login_attempts, :allowed_otp_drift_seconds, :otp_length,
:remember_otp_session_for_seconds, :otp_secret_encryption_key, :remember_otp_session_for_seconds, :otp_secret_encryption_key,
:direct_otp_length, :direct_otp_valid_for, :totp_timestamp, :delete_cookie_on_logout :direct_otp_length, :direct_otp_valid_for, :totp_timestamp, :delete_cookie_on_logout,
:issuer, :issuer_name, :logo_url
) )
end end
@ -51,9 +52,16 @@ module Devise
def provisioning_uri(account = nil, options = {}) def provisioning_uri(account = nil, options = {})
totp_secret = options[:otp_secret_key] || otp_secret_key totp_secret = options[:otp_secret_key] || otp_secret_key
options[:digits] ||= options[:otp_length] || self.class.otp_length options[:digits] ||= options[:otp_length] || self.class.otp_length
raise "provisioning_uri called with no otp_secret_key set" if totp_secret.nil? raise 'provisioning_uri called with no otp_secret_key set' if totp_secret.nil?
account ||= email if respond_to?(:email) account ||= email if respond_to?(:email)
ROTP::TOTP.new(totp_secret, options).provisioning_uri(account) options[:issuer] ||= self.class.issuer_name if self.class.issuer_name.present?
if self.class.logo_url.blank?
ROTP::TOTP.new(totp_secret, options).provisioning_uri(account)
else
image = "&image=#{self.class.logo_url}"
ROTP::TOTP.new(totp_secret, options).provisioning_uri(account) + image
end
end end
def need_two_factor_authentication?(request) def need_two_factor_authentication?(request)

Loading…
Cancel
Save