Skip to content

Commit 9a599e2

Browse files
committed
return unauthorized instead of forbidden on invalid token
1 parent 229c4a6 commit 9a599e2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

auth.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ func AuthHandler(subjects []string, verifier Verifier) http.Handler {
2828
auth := r.Header.Get("Authorization")
2929
jwt, err := parseAuthHeader(auth)
3030
if err != nil {
31-
w.WriteHeader(http.StatusForbidden)
31+
w.WriteHeader(http.StatusUnauthorized)
3232
_, _ = w.Write([]byte("Forbidden"))
33-
log.Info().Err(err).Dur("latency", time.Since(t)).Int("status", http.StatusForbidden).Msg("Forbidden")
33+
log.Info().Err(err).Dur("latency", time.Since(t)).Int("status", http.StatusUnauthorized).Msg("Unauthorized")
3434
return
3535
}
3636

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

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

0 commit comments

Comments
 (0)