Skip to content

Commit

Permalink
Add token header claims to tyk_context
Browse files Browse the repository at this point in the history
Right now we expose to context only body claims, this PR expose header
claims like `kid`  as well.

Should fix #1563
  • Loading branch information
buger committed Mar 23, 2018
1 parent 329c7fb commit 8381027
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mw_jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions mw_openid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8381027

Please sign in to comment.