Skip to content

Commit 399300e

Browse files
committed
fix: solved some minor errors (part III)
1 parent f29fa75 commit 399300e

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed

http/middleware/auth/authenticator.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ type Authenticator interface {
1212
rawToken string,
1313
failHandler func(
1414
w http.ResponseWriter,
15-
err string,
16-
httpStatus int,
15+
err error,
1716
errorCode *string,
1817
),
1918
refreshTokenFn func(

http/middleware/auth/errors.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ package auth
22

33
import (
44
"errors"
5-
gojwtnethttp "github.com/ralvarezdev/go-jwt/net/http"
6-
gonethttpresponse "github.com/ralvarezdev/go-net/http/response"
7-
"net/http"
85
)
96

107
var (
@@ -15,10 +12,5 @@ var (
1512

1613
var (
1714
ErrNilAuthenticator = errors.New("authenticator cannot be nil")
18-
ErrInvalidAuthorizationHeader = gonethttpresponse.NewFailResponseError(
19-
gojwtnethttp.AuthorizationHeaderKey,
20-
"invalid authorization header",
21-
ErrCodeInvalidAuthorizationHeader,
22-
http.StatusUnauthorized,
23-
)
15+
ErrInvalidAuthorizationHeader = errors.New("invalid authorization header")
2416
)

http/middleware/auth/middleware.go

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ func (m *Middleware) Authenticate(
4646
rawToken string,
4747
failHandler func(
4848
w http.ResponseWriter,
49-
err string,
49+
err error,
5050
errorCode *string,
51-
httpStatus int,
5251
),
5352
refreshTokenFn func(
5453
w http.ResponseWriter,
@@ -72,9 +71,8 @@ func (m *Middleware) Authenticate(
7271
) || refreshTokenFn == nil {
7372
failHandler(
7473
w,
75-
err.Error(),
74+
err,
7675
ErrCodeInvalidTokenClaims,
77-
http.StatusUnauthorized,
7876
)
7977
return
8078
}
@@ -83,9 +81,8 @@ func (m *Middleware) Authenticate(
8381
if err = refreshTokenFn(w, r); err != nil {
8482
failHandler(
8583
w,
86-
err.Error(),
84+
err,
8785
ErrCodeFailedToRefreshToken,
88-
http.StatusUnauthorized,
8986
)
9087
return
9188
}
@@ -115,17 +112,16 @@ func (m *Middleware) AuthenticateFromHeader(
115112
// Create the fail handler function
116113
failHandler := func(
117114
w http.ResponseWriter,
118-
err string,
115+
err error,
119116
errorCode *string,
120-
httpStatus int,
121117
) {
122118
m.handler.HandleError(
123119
w,
124120
gonethttpresponse.NewFailResponseError(
125121
gojwtnethttp.AuthorizationHeaderKey,
126-
err,
122+
err.Error(),
127123
errorCode,
128-
httpStatus,
124+
http.StatusUnauthorized,
129125
),
130126
)
131127
}
@@ -143,9 +139,8 @@ func (m *Middleware) AuthenticateFromHeader(
143139
if len(parts) < 2 || parts[0] != gojwt.BearerPrefix {
144140
failHandler(
145141
w,
146-
ErrInvalidAuthorizationHeader.Error(),
142+
ErrInvalidAuthorizationHeader,
147143
ErrCodeInvalidAuthorizationHeader,
148-
http.StatusUnauthorized,
149144
)
150145
return
151146
}
@@ -181,17 +176,16 @@ func (m *Middleware) AuthenticateFromCookie(
181176
// Create the fail handler function
182177
failHandler := func(
183178
w http.ResponseWriter,
184-
err string,
179+
err error,
185180
errorCode *string,
186-
httpStatus int,
187181
) {
188182
m.handler.HandleError(
189183
w,
190184
gonethttpresponse.NewFailResponseError(
191185
cookieName,
192-
err,
186+
err.Error(),
193187
errorCode,
194-
httpStatus,
188+
http.StatusUnauthorized,
195189
),
196190
)
197191
}
@@ -208,9 +202,8 @@ func (m *Middleware) AuthenticateFromCookie(
208202
if err != nil {
209203
failHandler(
210204
w,
211-
gonethttp.ErrCookieNotFound.Error(),
205+
gonethttp.ErrCookieNotFound,
212206
gonethttp.ErrCodeCookieNotFound,
213-
http.StatusUnauthorized,
214207
)
215208
return
216209
}

0 commit comments

Comments
 (0)