Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions route/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func validateMiddleware(next http.Handler) http.Handler {
if len(bearerToken) == 2 {
key, err := jwt.ParseRSAPublicKeyFromPEM([]byte(publicCertContent))
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode(exception{Message: err.Error()})
return
}
Expand All @@ -34,16 +35,22 @@ func validateMiddleware(next http.Handler) http.Handler {
return key, nil
})
if error != nil {
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode(exception{Message: error.Error()})
return
}
if token.Valid {
next.ServeHTTP(w, req)
} else {
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode(exception{Message: "Invalid authorization token"})
}
} else {
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode(exception{Message: "Invalid authorization token"})
}
} else {
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode(exception{Message: "An authorization header is required"})
}
})
Expand Down