package traefikllmgateway import "net/http" // requireAuth authenticates r, logs the outcome and, on refusal, writes the // 401 or 403 in the route's error shape (Anthropic when anthropic is true). func (g *Gateway) requireAuth(w http.ResponseWriter, r *http.Request, anthropic bool) (*user, *group, bool) { u, grp, st, reason := g.auth.authenticateDetail(r) g.logAuthEvent(st == authOK, authEventUserName(u), r, reason) write := writeOAIError if anthropic { write = writeAnthropicError } switch st { case authOK: return u, grp, true case authForbidden: write(w, http.StatusForbidden, "permission_error", "token has no group mapped for this gateway") default: write(w, http.StatusUnauthorized, "authentication_error", "invalid or missing API key") } return nil, nil, false }