Skip to content

Commit

Permalink
remove method/path from query
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard87 committed Apr 9, 2024
1 parent dc5b58a commit f90093c
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ func AuthHandler(subjects []string, verifier Verifier) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
t := time.Now()

event := log.Info().Str("method", r.Method).Str("path", r.URL.Path)

auth := r.Header.Get("Authorization")
jwt, err := parseAuthHeader(auth)
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
_, _ = w.Write([]byte("Forbidden"))
event.Err(err).Dur("elappsed_ms", time.Since(t)).Int("status", http.StatusUnauthorized).Msg("Unauthorized")
log.Info().Err(err).Dur("elappsed_ms", time.Since(t)).Int("status", http.StatusUnauthorized).Msg("Unauthorized")
return
}

Expand All @@ -41,7 +39,7 @@ func AuthHandler(subjects []string, verifier Verifier) http.Handler {
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
_, _ = w.Write([]byte("Forbidden"))
event.Err(err).Dur("elappsed_ms", time.Since(t)).Int("status", http.StatusUnauthorized).Msg("Unauthorized")
log.Info().Err(err).Dur("elappsed_ms", time.Since(t)).Int("status", http.StatusUnauthorized).Msg("Unauthorized")
return
}

Expand All @@ -50,13 +48,13 @@ func AuthHandler(subjects []string, verifier Verifier) http.Handler {
if !found {
w.WriteHeader(http.StatusForbidden)
_, _ = w.Write([]byte("Forbidden"))
event.Err(err).Dur("elappsed_ms", time.Since(t)).Int("status", http.StatusForbidden).Str("sub", subject).Msg("Forbidden")
log.Info().Err(err).Dur("elappsed_ms", time.Since(t)).Int("status", http.StatusForbidden).Str("sub", subject).Msg("Forbidden")
return
}

w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("OK"))
event.Dur("elappsed_ms", time.Since(t)).Int("status", http.StatusOK).Str("sub", subject).Msg("Authorized")
log.Info().Dur("elappsed_ms", time.Since(t)).Int("status", http.StatusOK).Str("sub", subject).Msg("Authorized")
})
}

Expand Down

0 comments on commit f90093c

Please sign in to comment.