Skip to content

Commit

Permalink
added extra middleware logging
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfg2610 committed Jul 20, 2020
1 parent 5a8ea7d commit a1d2004
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,11 @@ func (mid *JWTMiddleware) Verifier(next http.Handler) http.Handler {
}
bearerHeader := strings.Replace(bearerHeaderRaw, "Bearer ", "", -1)
if mid.EnableDebug {
fmt.Println("Cleaned bearer token: " + bearerHeaderRaw)
fmt.Println("Cleaned bearer token: " + bearerHeader)
}

tok, err := jwt.ParseSigned(bearerHeader)

var claims *jwt.Claims
if err != nil {
if mid.EnableDebug {
fmt.Println("Error getting claims: " + err.Error())
Expand All @@ -162,6 +161,7 @@ func (mid *JWTMiddleware) Verifier(next http.Handler) http.Handler {
return
}

var claims *jwt.Claims
for _, jwk := range mid.JWKS.Keys {
err = tok.Claims(jwk, &claims)

Expand All @@ -182,6 +182,9 @@ func (mid *JWTMiddleware) Verifier(next http.Handler) http.Handler {
ctx := context.WithValue(r.Context(), ContextJWTObject, tok)
ctx = context.WithValue(r.Context(), ContextJWTClaims, claims)

if mid.EnableDebug {
fmt.Println("Verifier passed, calling next http")
}
next.ServeHTTP(w, r.WithContext(ctx))
})
}
Expand Down Expand Up @@ -211,7 +214,9 @@ func (mid *JWTMiddleware) ClaimsValidator(next http.Handler) http.Handler {
next.ServeHTTP(w, r.WithContext(ctx))
return
}

if mid.EnableDebug {
fmt.Println("Claims validator passed")
}
next.ServeHTTP(w, r)
})
}
Expand All @@ -226,6 +231,10 @@ func (mid *JWTMiddleware) ClaimsTerminator(next http.Handler) http.Handler {
w.WriteHeader(http.StatusUnauthorized)
return
}

if mid.EnableDebug {
fmt.Println("Claims terminator passed")
}
next.ServeHTTP(w, r)
})
}

0 comments on commit a1d2004

Please sign in to comment.