Skip to content

Commit a3fb6bb

Browse files
authored
Merge pull request gin-contrib#32 from gin-contrib/update_status_code
change status code for invalid key to unauthorized
2 parents 0c33f40 + f8cd474 commit a3fb6bb

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

authenticator.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ func (a *Authenticator) Authenticated() gin.HandlerFunc {
9191

9292
secret, err := a.getSecret(sigHeader.keyID, sigHeader.algorithm)
9393
if err != nil {
94+
if err == ErrInvalidKeyID {
95+
_ = c.AbortWithError(http.StatusUnauthorized, err)
96+
return
97+
}
9498
_ = c.AbortWithError(http.StatusBadRequest, err)
9599
return
96100
}

authenticator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestAuthenticatedHeaderWrongKey(t *testing.T) {
9292
req.Header.Set(authorizationHeader, sigHeader)
9393
req.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
9494
c := runTest(secrets, requiredHeaders, nil, req)
95-
assert.Equal(t, http.StatusBadRequest, c.Writer.Status())
95+
assert.Equal(t, http.StatusUnauthorized, c.Writer.Status())
9696
assert.Equal(t, ErrInvalidKeyID, c.Errors[0])
9797
}
9898

0 commit comments

Comments
 (0)