Skip to content

Commit

Permalink
revs
Browse files Browse the repository at this point in the history
  • Loading branch information
jairad26 committed Oct 10, 2024
1 parent 897cfc1 commit 8cdbbc9
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions runtime/middleware/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,29 @@ func HandleJWT(next http.Handler) http.Handler {
}
}

if len(authPublicKeys) == 0 {
if !config.IsDevEnvironment() || tokenStr == "" {
next.ServeHTTP(w, r)
if config.IsDevEnvironment() {
if len(authPublicKeys) == 0 {
if tokenStr == "" {
next.ServeHTTP(w, r)
return
}
token, _, err := jwtParser.ParseUnverified(tokenStr, jwt.MapClaims{})
if err != nil {
logger.Warn(ctx).Err(err).Msg("Error parsing JWT token. Continuing since running in development")
next.ServeHTTP(w, r)
return
}
if claims, ok := token.Claims.(jwt.MapClaims); ok {
ctx = addClaimsToContext(ctx, claims)
}
next.ServeHTTP(w, r.WithContext(ctx))
return
}
token, _, err := jwtParser.ParseUnverified(tokenStr, jwt.MapClaims{})
if err != nil {
logger.Warn(ctx).Err(err).Msg("Error parsing JWT token. Continuing since running in development")
} else {
if len(authPublicKeys) == 0 {
next.ServeHTTP(w, r)
return
}
if claims, ok := token.Claims.(jwt.MapClaims); ok {
ctx = addClaimsToContext(ctx, claims)
}
next.ServeHTTP(w, r.WithContext(ctx))
return

}

var token *jwt.Token
Expand Down

0 comments on commit 8cdbbc9

Please sign in to comment.