Class: ForemanTasksCore::OtpManager
- Inherits:
-
Object
- Object
- ForemanTasksCore::OtpManager
- Defined in:
- lib/foreman_tasks_core/otp_manager.rb
Class Method Summary collapse
- .authenticate(hash, expected_user: nil, clear: true) ⇒ Object
- .drop_otp(username, password) ⇒ Object
- .generate_otp(username) ⇒ Object
- .passwords ⇒ Object
- .tokenize(username, password) ⇒ Object
Class Method Details
.authenticate(hash, expected_user: nil, clear: true) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/foreman_tasks_core/otp_manager.rb', line 20 def authenticate(hash, expected_user: nil, clear: true) plain = Base64.decode64(hash) username, otp = plain.split(':', 2) if expected_user return false unless expected_user == username end password_matches = passwords[username] == otp passwords.delete(username) if clear && password_matches password_matches end |
.drop_otp(username, password) ⇒ Object
12 13 14 |
# File 'lib/foreman_tasks_core/otp_manager.rb', line 12 def drop_otp(username, password) passwords.delete(username) if passwords[username] == password end |
.generate_otp(username) ⇒ Object
7 8 9 10 |
# File 'lib/foreman_tasks_core/otp_manager.rb', line 7 def generate_otp(username) otp = SecureRandom.hex passwords[username] = otp.to_s end |
.passwords ⇒ Object
16 17 18 |
# File 'lib/foreman_tasks_core/otp_manager.rb', line 16 def passwords @password ||= {} end |
.tokenize(username, password) ⇒ Object
31 32 33 |
# File 'lib/foreman_tasks_core/otp_manager.rb', line 31 def tokenize(username, password) Base64.strict_encode64("#{username}:#{password}") end |