discourse/lib/webauthn/challenge_generator.rb
Penar Musaraj 006a5166e5
DEV: Refactor rp_id and rp_name (#23339)
They're both constant per-instance values, there is no need to store them
in the session. This also makes the code a bit more readable by moving
the `session_challenge_key` method up to the `DiscourseWebauthn` module.
2023-08-31 09:11:23 -04:00

23 lines
485 B
Ruby

# frozen_string_literal: true
module DiscourseWebauthn
class ChallengeGenerator
class ChallengeSession
attr_reader :challenge
def initialize(params)
@challenge = params[:challenge]
end
def commit_to_session(secure_session, user)
secure_session[DiscourseWebauthn.session_challenge_key(user)] = @challenge
self
end
end
def self.generate
ChallengeSession.new(challenge: SecureRandom.hex(30))
end
end
end