Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.

Commit fe47fe6

Browse files
authored
Add help to retreive user claims from ctx (#22)
**What** - In the pgql server we need to retreive the user claims from an arbitrary context, not directly from a request object, because the request context and passed to the required location indirectly. This new helper supports that Signed-off-by: Lucas Roesler <[email protected]>
1 parent fe27e62 commit fe47fe6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pkg/http/middlewares/authorization/claims.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ func (a *Claims) Entities() (entities []string) {
116116

117117
// GetClaims retrieves the Claims object from the request context
118118
func GetClaims(r *http.Request) (Claims, bool) {
119-
claims, ok := r.Context().Value(authClaimsKey).(Claims)
119+
claims, ok := GetClaimsFromCtx(r.Context())
120+
return claims, ok
121+
}
122+
123+
// GetClaimsFromCtx retrieves the Claims object from the given context
124+
func GetClaimsFromCtx(ctx context.Context) (Claims, bool) {
125+
claims, ok := ctx.Value(authClaimsKey).(Claims)
120126
return claims, ok
121127
}
122128

0 commit comments

Comments
 (0)