2020-01-10 08:45:56 +08:00
|
|
|
# frozen_string_literal: true
|
2023-08-18 20:39:10 +08:00
|
|
|
module DiscourseWebauthn
|
2020-01-10 08:45:56 +08:00
|
|
|
class ChallengeGenerator
|
|
|
|
class ChallengeSession
|
2023-08-31 21:11:23 +08:00
|
|
|
attr_reader :challenge
|
2020-01-10 08:45:56 +08:00
|
|
|
|
|
|
|
def initialize(params)
|
|
|
|
@challenge = params[:challenge]
|
|
|
|
end
|
|
|
|
|
|
|
|
def commit_to_session(secure_session, user)
|
2023-08-31 21:11:23 +08:00
|
|
|
secure_session[DiscourseWebauthn.session_challenge_key(user)] = @challenge
|
2020-01-10 08:45:56 +08:00
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.generate
|
2023-08-31 21:11:23 +08:00
|
|
|
ChallengeSession.new(challenge: SecureRandom.hex(30))
|
2020-01-10 08:45:56 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|