Skip to content

Commit 466d509

Browse files
committed
Fixed #938
Signed-off-by: Vishal Rana <vr@labstack.com>
1 parent 3359eae commit 466d509

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

middleware/basic_auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type (
2323
}
2424

2525
// BasicAuthValidator defines a function to validate BasicAuth credentials.
26-
BasicAuthValidator func(string, string, echo.Context) (error, bool)
26+
BasicAuthValidator func(string, string, echo.Context) (bool, error)
2727
)
2828

2929
const (
@@ -81,7 +81,7 @@ func BasicAuthWithConfig(config BasicAuthConfig) echo.MiddlewareFunc {
8181
for i := 0; i < len(cred); i++ {
8282
if cred[i] == ':' {
8383
// Verify credentials
84-
err, valid := config.Validator(cred[:i], cred[i+1:], c)
84+
valid, err := config.Validator(cred[:i], cred[i+1:], c)
8585
if err != nil {
8686
return err
8787
} else if valid {

middleware/basic_auth_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ func TestBasicAuth(t *testing.T) {
1515
req := httptest.NewRequest(echo.GET, "/", nil)
1616
res := httptest.NewRecorder()
1717
c := e.NewContext(req, res)
18-
f := func(u, p string, c echo.Context) (error, bool) {
18+
f := func(u, p string, c echo.Context) (bool, error) {
1919
if u == "joe" && p == "secret" {
20-
return nil, true
20+
return true, nil
2121
}
22-
return nil, false
22+
return false, nil
2323
}
2424
h := BasicAuth(f)(func(c echo.Context) error {
2525
return c.String(http.StatusOK, "test")

middleware/key_auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type (
3232
}
3333

3434
// KeyAuthValidator defines a function to validate KeyAuth credentials.
35-
KeyAuthValidator func(string, echo.Context) (error, bool)
35+
KeyAuthValidator func(string, echo.Context) (bool, error)
3636

3737
keyExtractor func(echo.Context) (string, error)
3838
)
@@ -94,7 +94,7 @@ func KeyAuthWithConfig(config KeyAuthConfig) echo.MiddlewareFunc {
9494
if err != nil {
9595
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
9696
}
97-
err, valid := config.Validator(key, c)
97+
valid, err := config.Validator(key, c)
9898
if err != nil {
9999
return err
100100
} else if valid {

middleware/key_auth_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ func TestKeyAuth(t *testing.T) {
1515
res := httptest.NewRecorder()
1616
c := e.NewContext(req, res)
1717
config := KeyAuthConfig{
18-
Validator: func(key string, c echo.Context) (error, bool) {
19-
return nil, key == "valid-key"
18+
Validator: func(key string, c echo.Context) (bool, error) {
19+
return key == "valid-key", nil
2020
},
2121
}
2222
h := KeyAuthWithConfig(config)(func(c echo.Context) error {

0 commit comments

Comments
 (0)