From a1d2004dfc1426e2c66a8734a6130ee40517bc5a Mon Sep 17 00:00:00 2001 From: John Date: Mon, 20 Jul 2020 08:56:15 +0100 Subject: [PATCH] added extra middleware logging --- middleware.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/middleware.go b/middleware.go index fef757e..3bd6323 100644 --- a/middleware.go +++ b/middleware.go @@ -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()) @@ -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) @@ -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)) }) } @@ -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) }) } @@ -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) }) }