From 06fd304051d972f7059bdcfcb56d86d42b6ca36f Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Mon, 16 May 2022 22:43:42 +0200 Subject: [PATCH] Fix scope handling. The http context of the authenticated request was not properly forward to the next handlers. So, even if the request was authenticated, the next handlers doesn't see actual scopes of the agent. --- cmd/container.go | 3 +++ pkg/api/routes/routes.go | 1 + 2 files changed, 4 insertions(+) diff --git a/cmd/container.go b/cmd/container.go index 734fa3a5b..e44bd1687 100644 --- a/cmd/container.go +++ b/cmd/container.go @@ -273,6 +273,9 @@ func NewContainer(v *viper.Viper, userOptions ...fx.Option) *fx.App { handled := false sharedauth.Middleware(methods...)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { handled = true + // The middleware replace the context of the request to include the agent + // We have to forward it to gin + c.Request = r c.Next() })).ServeHTTP(c.Writer, c.Request) if !handled { diff --git a/pkg/api/routes/routes.go b/pkg/api/routes/routes.go index cff9e8cb3..954ee7c99 100644 --- a/pkg/api/routes/routes.go +++ b/pkg/api/routes/routes.go @@ -109,6 +109,7 @@ func (r *Routes) wrapWithScopes(handler gin.HandlerFunc, scopes ...string) gin.H return func(context *gin.Context) { ok := false sharedauth.NeedOneOfScopes(scopes...)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + context.Request = r ok = true })).ServeHTTP(context.Writer, context.Request) if !ok {