Skip to content

Commit 1dede22

Browse files
Fix authentication middleware: JWT auth works completed fine
1 parent 19dcc60 commit 1dede22

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

api/routes/routes.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ func RegisterRoutes(mux *http.ServeMux) {
1313

1414
/* for monitoring the state of overall server and laclm backend */
1515
mux.Handle("GET /health", http.HandlerFunc(
16-
middleware.LoggingMiddleware(health.HealthHandler),
16+
middleware.LoggingMiddleware(
17+
middleware.AuthenticationMiddleware(health.HealthHandler),
18+
),
1719
))
1820

1921
/* for logging into the backend and creating a session */

internal/auth/auth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ func ValidateJWT(tokenString string) (jwt.MapClaims, error) {
3333
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
3434
return nil, fmt.Errorf("unexpected signing method")
3535
}
36-
return config.BackendConfig.BackendSecurity.JWTTokenSecret, nil
36+
return []byte(config.BackendConfig.BackendSecurity.JWTTokenSecret), nil
3737
})
3838

3939
if err != nil {
40-
return nil, err
40+
return nil, fmt.Errorf("JWT parsing error: %w", err)
4141
}
4242

4343
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
@@ -53,7 +53,7 @@ func GetUsernameFromJWT(tokenString string) (string, error) {
5353
/* get claims from JWT Token */
5454
claims, err := ValidateJWT(tokenString)
5555
if err != nil {
56-
return "", err
56+
return "", fmt.Errorf("JWT validation error: %w", err)
5757
}
5858

5959
/* extract username from JWT Token */

0 commit comments

Comments
 (0)