mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
feat: wire durable session authentication into API
This commit is contained in:
+13
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user