diff options
Diffstat (limited to 'weed/s3api/s3_constants/header.go')
| -rw-r--r-- | weed/s3api/s3_constants/header.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/weed/s3api/s3_constants/header.go b/weed/s3api/s3_constants/header.go index a232eb189..377f355f6 100644 --- a/weed/s3api/s3_constants/header.go +++ b/weed/s3api/s3_constants/header.go @@ -178,7 +178,8 @@ func IsSeaweedFSInternalHeader(headerKey string) bool { type contextKey string const ( - contextKeyIdentityName contextKey = "s3-identity-name" + contextKeyIdentityName contextKey = "s3-identity-name" + contextKeyIdentityObject contextKey = "s3-identity-object" ) // SetIdentityNameInContext stores the authenticated identity name in the request context @@ -199,3 +200,18 @@ func GetIdentityNameFromContext(r *http.Request) string { } return "" } + +// SetIdentityInContext stores the full authenticated identity object in the request context +// This is used to pass the full identity (including for JWT users) to handlers +func SetIdentityInContext(ctx context.Context, identity interface{}) context.Context { + if identity != nil { + return context.WithValue(ctx, contextKeyIdentityObject, identity) + } + return ctx +} + +// GetIdentityFromContext retrieves the full identity object from the request context +// Returns nil if no identity is set (unauthenticated request) +func GetIdentityFromContext(r *http.Request) interface{} { + return r.Context().Value(contextKeyIdentityObject) +} |
