Module: Istox::Vault::TOTP
- Defined in:
- lib/istox/helpers/vault.rb
Class Method Summary collapse
Class Method Details
.create(sid, host) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/istox/helpers/vault.rb', line 7 def create(sid, host) Rails.logger.debug { "Generate vault TOTP for key #{totp_key(sid).inspect}" } write_data(totp_key(sid), generate: true, issuer: host, account_name: sid, period: 300, qr_size: 300) end |
.generate_code(sid) ⇒ Object
18 19 20 21 |
# File 'lib/istox/helpers/vault.rb', line 18 def generate_code(sid) Rails.logger.debug { "Generate 6-digit OTP code: key #{totp_code_key(sid)}" } read_data(totp_code_key(sid)).data[:code] end |
.validate?(sid, code) ⇒ Boolean
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/istox/helpers/vault.rb', line 23 def validate?(sid, code) Rails.logger.debug { "Validate TOTP code: key #{totp_code_key(sid)}, code: #{code}" } result = write_data(totp_code_key(sid), code: code).data[:valid] unless result code = read_data(totp_code_key(sid)).data[:code] Rails.logger.debug { "Code is not valid, it should be #{code}" } end result end |