FEATURE: add ability to have multiple totp factors (#7626)

Adds a second factor landing page that centralizes a user's second factor configuration.

This contains both TOTP and Backup, and also allows multiple TOTP tokens to be registered and organized by a name. Access to this page is authenticated via password, and cached for 30 minutes via a secure session.
This commit is contained in:
Jeff Wong
2019-06-26 16:58:06 -07:00
committed by GitHub
parent b2a033e92b
commit 88ef5e55fe
25 changed files with 793 additions and 549 deletions

View File

@ -11,6 +11,10 @@ class UserSecondFactor < ActiveRecord::Base
where(method: UserSecondFactor.methods[:totp], enabled: true)
end
scope :all_totps, -> do
where(method: UserSecondFactor.methods[:totp])
end
def self.methods
@methods ||= Enum.new(
totp: 1,
@ -18,8 +22,12 @@ class UserSecondFactor < ActiveRecord::Base
)
end
def self.totp
where(method: self.methods[:totp]).first
def get_totp_object
ROTP::TOTP.new(self.data, issuer: SiteSetting.title)
end
def totp_provisioning_uri
get_totp_object.provisioning_uri(user.email)
end
end