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