@@ -3,6 +3,7 @@ package jwt
3
3
import (
4
4
"context"
5
5
"errors"
6
+ "fmt"
6
7
"io"
7
8
"net/http"
8
9
@@ -12,23 +13,27 @@ import (
12
13
func (f * Factory ) HTTPAuthHandler (proxy auth.Proxy ) http.Handler {
13
14
return http .HandlerFunc (func (writer http.ResponseWriter , request * http.Request ) {
14
15
credential , err := io .ReadAll (request .Body )
15
- if err != nil { //nolint:staticcheck,revive
16
- // ...
16
+ if err != nil {
17
+ http .Error (writer , fmt .Errorf ("failed to read request body credential: %w" , err ).Error (), http .StatusBadRequest )
18
+ return
17
19
}
18
20
19
21
id , err := proxy .Authenticate (context .Background (), credential )
20
- if err != nil { //nolint:staticcheck,revive
21
- // ...
22
+ if err != nil {
23
+ http .Error (writer , fmt .Errorf ("failed to authenticate: %w" , err ).Error (), http .StatusUnauthorized )
24
+ return
22
25
}
23
26
24
27
token , err := f .IssueJWT (id )
25
- if err != nil { //nolint:staticcheck,revive
26
- // ...
28
+ if err != nil {
29
+ http .Error (writer , fmt .Errorf ("failed to issue JWT: %w" , err ).Error (), http .StatusInternalServerError )
30
+ return
27
31
}
28
32
29
33
writer .Header ().Set ("Content-Type" , "application/json" )
30
- if _ , err := writer .Write ([]byte (token )); err != nil { //nolint:staticcheck,revive
31
- // ...
34
+ if _ , err := writer .Write ([]byte (token )); err != nil {
35
+ http .Error (writer , fmt .Errorf ("failed to write response: %w" , err ).Error (), http .StatusInternalServerError )
36
+ return
32
37
}
33
38
})
34
39
}
@@ -37,8 +42,7 @@ func (f *Factory) VerifyHTTPMiddleware(next auth.AuthenticatedHandler) http.Hand
37
42
return http .HandlerFunc (func (writer http.ResponseWriter , request * http.Request ) {
38
43
id , err := f .VerifyHTTPRequest (request )
39
44
if err != nil {
40
- writer .WriteHeader (http .StatusUnauthorized )
41
- writer .Write ([]byte (err .Error ())) //nolint:errcheck
45
+ http .Error (writer , err .Error (), http .StatusUnauthorized )
42
46
return
43
47
}
44
48
0 commit comments