From 838102719e0c3a4bc74ac3b15ba751c48bed435a Mon Sep 17 00:00:00 2001 From: Leonid Bugaev Date: Fri, 23 Mar 2018 16:52:40 +0300 Subject: [PATCH] Add token header claims to tyk_context Right now we expose to context only body claims, this PR expose header claims like `kid` as well. Should fix https://github.com/TykTechnologies/tyk/issues/1563 --- mw_jwt.go | 5 +++++ mw_openid.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/mw_jwt.go b/mw_jwt.go index 665235fc6b7..bebd7125a10 100644 --- a/mw_jwt.go +++ b/mw_jwt.go @@ -451,6 +451,11 @@ func (k *JWTMiddleware) setContextVars(r *http.Request, token *jwt.Token) { if cnt := ctxGetData(r); cnt != nil { claimPrefix := "jwt_claims_" + for claimName, claimValue := range token.Header { + claim := claimPrefix + claimName + cnt[claim] = claimValue + } + for claimName, claimValue := range token.Claims.(jwt.MapClaims) { claim := claimPrefix + claimName cnt[claim] = claimValue diff --git a/mw_openid.go b/mw_openid.go index 63d0a9b9959..c61ef77770b 100644 --- a/mw_openid.go +++ b/mw_openid.go @@ -234,6 +234,11 @@ func (k *OpenIDMW) setContextVars(r *http.Request, token *jwt.Token) { } claimPrefix := "jwt_claims_" + for claimName, claimValue := range token.Header { + claim := claimPrefix + claimName + cnt[claim] = claimValue + } + for claimName, claimValue := range token.Claims.(jwt.MapClaims) { claim := claimPrefix + claimName cnt[claim] = claimValue