feat(auth): per-caller Gitea PAT pass-through (#59)
Replaces the shared GITEA_MCP_DEFAULT_TOKEN for all callers. When a request's bearer validates directly against Gitea's own /api/v1/user, that token is used for every upstream call this request makes instead of the service PAT, and the caller identity comes from Gitea's own login rather than the proxy header. Any other bearer (static token, JWT, none) falls through unchanged to the existing chassis auth. Prep: Authentik now SSOs into Gitea (infra a32801c), so each real user can mint their own PAT from their own linked account. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -36,11 +36,14 @@ func CallerMiddleware(logger *slog.Logger, next http.Handler) http.Handler {
|
||||
"x_forwarded_user", fwdUser)
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), ctxKey{}, user)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
next.ServeHTTP(w, r.WithContext(withCaller(r.Context(), user)))
|
||||
})
|
||||
}
|
||||
|
||||
func withCaller(ctx context.Context, user string) context.Context {
|
||||
return context.WithValue(ctx, ctxKey{}, user)
|
||||
}
|
||||
|
||||
func Caller(ctx context.Context) string {
|
||||
if v, ok := ctx.Value(ctxKey{}).(string); ok {
|
||||
return v
|
||||
|
||||
Reference in New Issue
Block a user