feat: wire durable session authentication into API

This commit is contained in:
Josh Creek
2026-08-31 22:24:51 +01:00
parent b3284d4bd6
commit a2a7107dd7
3 changed files with 39 additions and 3 deletions
+13 -2
View File
@@ -30,8 +30,13 @@ type QueueBackend interface {
Get(context.Context, string, string, time.Time) (domain.QueueTicket, error)
}
type SessionBackend interface {
Authenticate(context.Context, string, string, time.Time) (domain.Session, error)
}
type Service struct {
Sessions *domain.SessionStore
SessionBackend SessionBackend
Queue *domain.Queue
Candidate CandidateProvider
CandidateV2 CandidateProviderV2
@@ -330,7 +335,7 @@ func (s *Service) probe(w http.ResponseWriter, r *http.Request) {
}
func (s *Service) authenticate(w http.ResponseWriter, r *http.Request) (string, bool) {
if s.Sessions == nil {
if s.Sessions == nil && s.SessionBackend == nil {
writeError(w, http.StatusServiceUnavailable, "auth_unavailable")
return "", false
}
@@ -344,7 +349,13 @@ func (s *Service) authenticate(w http.ResponseWriter, r *http.Request) (string,
writeError(w, http.StatusUnauthorized, "unauthorized")
return "", false
}
session, err := s.Sessions.Authenticate(parts[1][:separator], parts[1][separator+1:], s.now())
var session domain.Session
var err error
if s.SessionBackend != nil {
session, err = s.SessionBackend.Authenticate(r.Context(), parts[1][:separator], parts[1][separator+1:], s.now())
} else {
session, err = s.Sessions.Authenticate(parts[1][:separator], parts[1][separator+1:], s.now())
}
if err != nil {
writeError(w, http.StatusUnauthorized, "unauthorized")
return "", false