diff --git a/changelog/unreleased/initiator-ids.md b/changelog/unreleased/initiator-ids.md index 013fa2bec..d0d0f2136 100644 --- a/changelog/unreleased/initiator-ids.md +++ b/changelog/unreleased/initiator-ids.md @@ -2,4 +2,5 @@ Enhancement: Initiator-IDs Allows sending a header `Initiator-ID` on http requests. This id will be added to sse events so clients can figure out if their particular instance was triggering the event. Additionally this adds the etag of the file/folder to all sse events. +https://github.com/owncloud/ocis/pull/8936 https://github.com/owncloud/ocis/pull/8701 diff --git a/services/graph/pkg/middleware/auth.go b/services/graph/pkg/middleware/auth.go index 6b06da06e..0c7fee4ee 100644 --- a/services/graph/pkg/middleware/auth.go +++ b/services/graph/pkg/middleware/auth.go @@ -7,6 +7,7 @@ import ( "google.golang.org/grpc/metadata" "github.com/cs3org/reva/v2/pkg/auth/scope" + ctxpkg "github.com/cs3org/reva/v2/pkg/ctx" revactx "github.com/cs3org/reva/v2/pkg/ctx" "github.com/cs3org/reva/v2/pkg/token/manager/jwt" "github.com/owncloud/ocis/v2/ocis-pkg/account" @@ -75,14 +76,20 @@ func Auth(opts ...account.Option) func(http.Handler) http.Handler { ctx = revactx.ContextSetToken(ctx, t) ctx = revactx.ContextSetUser(ctx, u) - ctx = gmmetadata.Set(ctx, opkgm.AccountID, u.Id.OpaqueId) - if u.Opaque != nil && u.Opaque.Map != nil { - if roles, ok := u.Opaque.Map["roles"]; ok { - ctx = gmmetadata.Set(ctx, opkgm.RoleIDs, string(roles.Value)) + ctx = gmmetadata.Set(ctx, opkgm.AccountID, u.GetId().GetOpaqueId()) + if m := u.GetOpaque().GetMap(); m != nil { + if roles, ok := m["roles"]; ok { + ctx = gmmetadata.Set(ctx, opkgm.RoleIDs, string(roles.GetValue())) } } ctx = metadata.AppendToOutgoingContext(ctx, revactx.TokenHeader, t) + initiatorID := r.Header.Get(ctxpkg.InitiatorHeader) + if initiatorID != "" { + ctx = ctxpkg.ContextSetInitiator(ctx, initiatorID) + ctx = metadata.AppendToOutgoingContext(ctx, ctxpkg.InitiatorHeader, initiatorID) + } + next.ServeHTTP(w, r.WithContext(ctx)) }) }