diff --git a/lib/two_factor_authentication.rb b/lib/two_factor_authentication.rb index 7b1bbbc..0600366 100644 --- a/lib/two_factor_authentication.rb +++ b/lib/two_factor_authentication.rb @@ -32,6 +32,12 @@ module Devise mattr_accessor :delete_cookie_on_logout @@delete_cookie_on_logout = false + + mattr_accessor :issuer_name + @@issuer = '' + + mattr_accessor :logo_url + @@logo_url = '' end module TwoFactorAuthentication diff --git a/lib/two_factor_authentication/models/two_factor_authenticatable.rb b/lib/two_factor_authentication/models/two_factor_authenticatable.rb index d23cae8..eb6c064 100644 --- a/lib/two_factor_authentication/models/two_factor_authenticatable.rb +++ b/lib/two_factor_authentication/models/two_factor_authenticatable.rb @@ -16,7 +16,8 @@ module Devise ::Devise::Models.config( self, :max_login_attempts, :allowed_otp_drift_seconds, :otp_length, :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 @@ -51,9 +52,16 @@ module Devise def provisioning_uri(account = nil, options = {}) totp_secret = options[:otp_secret_key] || otp_secret_key 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) - 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 def need_two_factor_authentication?(request)