generated from VLADIMIR/template
update claims
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package processor_jwt
|
||||
|
||||
import "context"
|
||||
|
||||
type claimsContextKey struct{}
|
||||
|
||||
// ContextWithClaims stores authenticated claims in ctx.
|
||||
func ContextWithClaims(ctx context.Context, claims *JWTClaims) context.Context {
|
||||
return context.WithValue(ctx, claimsContextKey{}, claims)
|
||||
}
|
||||
|
||||
// ClaimsFromContext returns authenticated claims stored in ctx.
|
||||
func ClaimsFromContext(ctx context.Context) (*JWTClaims, bool) {
|
||||
claims, ok := ctx.Value(claimsContextKey{}).(*JWTClaims)
|
||||
return claims, ok && claims != nil
|
||||
}
|
||||
@@ -39,7 +39,7 @@ func NewAuthorizationInterceptor(
|
||||
return nil, status.Errorf(codes.Unauthenticated, "invalid token")
|
||||
}
|
||||
|
||||
ctx = context.WithValue(ctx, "claims", claims)
|
||||
ctx = ContextWithClaims(ctx, claims)
|
||||
return handler(ctx, req)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user