Skip to content

Commit

Permalink
Fix scope handling.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gfyrag committed May 17, 2022
1 parent 818b763 commit 06fd304
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/api/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 06fd304

Please sign in to comment.