diff --git a/changelog/unreleased/initiator-ids.md b/changelog/unreleased/initiator-ids.md index 013fa2bec5d..d0d0f21368a 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 6b06da06eae..0c7fee4ee94 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)) }) }