discourse/lib/discourse_webauthn/challenge_generator.rb
Loïc Guitaut b4e4833d2a DEV: Rename SecureSession to ServerSession
This patch will be followed by
https://github.com/discourse/discourse/pull/34747.

`SecureSession` doesn’t make a lot of sense anymore and can be confusing
as the current cookie store used for the session is actually secure
since it’s encrypted.

Renaming it to `ServerSession` better conveys what it does: providing a
session but on the server side only.

This patch also makes some improvements, like injecting that server
session into Rack-like request objects, allowing the server session to
be available virtually everywhere.
2025-09-18 16:31:03 +02:00

21 lines
529 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(server_session, user, expires: server_session.expiry)
server_session.set(DiscourseWebauthn.session_challenge_key(user), @challenge, expires:)
self
end
end
def self.generate
ChallengeSession.new(challenge: SecureRandom.hex(30))
end
end
end