Skip to content

Commit

Permalink
return unauthorized instead of forbidden on invalid token
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard87 committed Apr 9, 2024
1 parent 229c4a6 commit 9a599e2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ func AuthHandler(subjects []string, verifier Verifier) http.Handler {
auth := r.Header.Get("Authorization")
jwt, err := parseAuthHeader(auth)
if err != nil {
w.WriteHeader(http.StatusForbidden)
w.WriteHeader(http.StatusUnauthorized)
_, _ = w.Write([]byte("Forbidden"))
log.Info().Err(err).Dur("latency", time.Since(t)).Int("status", http.StatusForbidden).Msg("Forbidden")
log.Info().Err(err).Dur("latency", time.Since(t)).Int("status", http.StatusUnauthorized).Msg("Unauthorized")
return
}

token, err := verifier.Verify(r.Context(), jwt)

if err != nil {
w.WriteHeader(http.StatusForbidden)
w.WriteHeader(http.StatusUnauthorized)
_, _ = w.Write([]byte("Forbidden"))
log.Info().Err(err).Dur("latency", time.Since(t)).Int("status", http.StatusForbidden).Msg("Forbidden")
log.Info().Err(err).Dur("latency", time.Since(t)).Int("status", http.StatusUnauthorized).Msg("Unauthorized")
return
}

Expand Down

0 comments on commit 9a599e2

Please sign in to comment.