Sync shared snapshot from 7b5a4e6
This commit is contained in:
1 parent
695ff742d6
commit
68f6dd5a87
47 files changed
+587
-726
No files matched your search
@@ -131,6 +131,7 @@ import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
sharedauth "repos.gfranz.ch/Gabriel20xx/shared/backend/auth"
|
||||
authclient "repos.gfranz.ch/Gabriel20xx/shared/backend/authclient"
|
||||
"repos.gfranz.ch/Gabriel20xx/shared/backend/authproxy"
|
||||
)
|
||||
|
||||
// User is this service's own /auth/... response shape - UNCHANGED from
|
||||
@@ -222,25 +223,14 @@ func UserFromContext(ctx context.Context) *User {
|
||||
// sessionToken reads the AuthGuard session cookie off the incoming request.
|
||||
// See the top-of-file doc comment's "Session cookie / token model" section.
|
||||
func (s *Service) sessionToken(r *http.Request) string {
|
||||
cookie, err := r.Cookie(authclient.DefaultCookieName)
|
||||
if err != nil || cookie.Value == "" {
|
||||
return ""
|
||||
}
|
||||
return cookie.Value
|
||||
return authproxy.SessionToken(r)
|
||||
}
|
||||
|
||||
// clearSessionCookies clears both the AuthGuard cookie (as a fallback -
|
||||
// normally AuthGuard's own Set-Cookie, forwarded via authclient.ForwardCookies,
|
||||
// already does this) and the pre-migration cookie name.
|
||||
func (s *Service) clearSessionCookies(w http.ResponseWriter) {
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: authclient.DefaultCookieName, Value: "", Path: "/", HttpOnly: true,
|
||||
Secure: s.secureCookies, SameSite: http.SameSiteLaxMode, MaxAge: -1,
|
||||
})
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: s.cookieName, Value: "", Path: "/", HttpOnly: true,
|
||||
Secure: s.secureCookies, SameSite: http.SameSiteLaxMode, MaxAge: -1,
|
||||
})
|
||||
authproxy.ClearSessionCookies(w, s.cookieName, s.secureCookies)
|
||||
}
|
||||
|
||||
// toUser translates AuthGuard's PublicUser into this service's own User
|
||||
@@ -1144,9 +1134,8 @@ func (s *Service) SetPassword(ctx context.Context, id int64, password string) er
|
||||
// non-APIError (a transport failure actually reaching AuthGuard) falls back
|
||||
// to a generic 500 with fallbackMessage.
|
||||
func writeAuthGuardError(w http.ResponseWriter, err error, fallbackMessage string) {
|
||||
var apiErr *authclient.APIError
|
||||
if errors.As(err, &apiErr) {
|
||||
writeError(w, apiErr.StatusCode, apiErr.Message)
|
||||
if statusCode, message, ok := authproxy.APIErrorResponse(err); ok {
|
||||
writeError(w, statusCode, message)
|
||||
return
|
||||
}
|
||||
writeError(w, http.StatusInternalServerError, fallbackMessage)
|
||||
|
||||
@@ -18,7 +18,6 @@ const (
|
||||
Moderator Service = "moderator"
|
||||
Kiosk Service = "kiosk"
|
||||
Servant Service = "servant"
|
||||
Desktop Service = "desktop"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -137,8 +136,6 @@ func normalizeService(value string) Service {
|
||||
return Kiosk
|
||||
case "servant", "mediaservant":
|
||||
return Servant
|
||||
case "desktop", "mediadesktop":
|
||||
return Desktop
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
@@ -160,8 +157,6 @@ func serviceName(service Service) string {
|
||||
return "MediaKiosk"
|
||||
case Servant:
|
||||
return "MediaServant"
|
||||
case Desktop:
|
||||
return "MediaDesktop"
|
||||
default:
|
||||
return "MediaCollection"
|
||||
}
|
||||
|
||||
@@ -1060,12 +1060,6 @@ func (s *Server) kioskStatus(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "latestImage": latest, "queueLength": 0})
|
||||
}
|
||||
|
||||
func (s *Server) mountDesktopRoutes(r chi.Router) {
|
||||
r.Get("/status", func(w http.ResponseWriter, _ *http.Request) {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "service": "MediaDesktop", "native": true})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) mountKioskSocket(r chi.Router) {
|
||||
r.Get("/ws", s.kioskWebsocket)
|
||||
}
|
||||
|
||||
@@ -223,8 +223,6 @@ func (s *Server) mountServiceRoutes(r chi.Router) {
|
||||
s.mountKioskRoutes(r)
|
||||
case config.Servant:
|
||||
s.mountServantRoutes(r)
|
||||
case config.Desktop:
|
||||
s.mountDesktopRoutes(r)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user