class Proxy::Dynflow::OtpManager

Public Class Methods

authenticate(hash, expected_user: nil, clear: true) click to toggle source
# File lib/smart_proxy_dynflow/otp_manager.rb, line 22
def authenticate(hash, expected_user: nil, clear: true)
  plain = Base64.decode64(hash)
  username, otp = plain.split(':', 2)
  if expected_user && expected_user != username
    return false
  end

  password_matches = passwords[username] == otp
  passwords.delete(username) if clear && password_matches
  password_matches
end
drop_otp(username, password) click to toggle source
# File lib/smart_proxy_dynflow/otp_manager.rb, line 14
def drop_otp(username, password)
  passwords.delete(username) if passwords[username] == password
end
generate_otp(username) click to toggle source
# File lib/smart_proxy_dynflow/otp_manager.rb, line 9
def generate_otp(username)
  otp = SecureRandom.hex
  passwords[username] = otp.to_s
end
passwords() click to toggle source
# File lib/smart_proxy_dynflow/otp_manager.rb, line 18
def passwords
  @password ||= {}
end
tokenize(username, password) click to toggle source
# File lib/smart_proxy_dynflow/otp_manager.rb, line 34
def tokenize(username, password)
  Base64.strict_encode64("#{username}:#{password}")
end