mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
parent
3359eae306
commit
466d509e34
@ -23,7 +23,7 @@ type (
|
||||
}
|
||||
|
||||
// BasicAuthValidator defines a function to validate BasicAuth credentials.
|
||||
BasicAuthValidator func(string, string, echo.Context) (error, bool)
|
||||
BasicAuthValidator func(string, string, echo.Context) (bool, error)
|
||||
)
|
||||
|
||||
const (
|
||||
@ -81,7 +81,7 @@ func BasicAuthWithConfig(config BasicAuthConfig) echo.MiddlewareFunc {
|
||||
for i := 0; i < len(cred); i++ {
|
||||
if cred[i] == ':' {
|
||||
// Verify credentials
|
||||
err, valid := config.Validator(cred[:i], cred[i+1:], c)
|
||||
valid, err := config.Validator(cred[:i], cred[i+1:], c)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if valid {
|
||||
|
@ -15,11 +15,11 @@ func TestBasicAuth(t *testing.T) {
|
||||
req := httptest.NewRequest(echo.GET, "/", nil)
|
||||
res := httptest.NewRecorder()
|
||||
c := e.NewContext(req, res)
|
||||
f := func(u, p string, c echo.Context) (error, bool) {
|
||||
f := func(u, p string, c echo.Context) (bool, error) {
|
||||
if u == "joe" && p == "secret" {
|
||||
return nil, true
|
||||
return true, nil
|
||||
}
|
||||
return nil, false
|
||||
return false, nil
|
||||
}
|
||||
h := BasicAuth(f)(func(c echo.Context) error {
|
||||
return c.String(http.StatusOK, "test")
|
||||
|
@ -32,7 +32,7 @@ type (
|
||||
}
|
||||
|
||||
// KeyAuthValidator defines a function to validate KeyAuth credentials.
|
||||
KeyAuthValidator func(string, echo.Context) (error, bool)
|
||||
KeyAuthValidator func(string, echo.Context) (bool, error)
|
||||
|
||||
keyExtractor func(echo.Context) (string, error)
|
||||
)
|
||||
@ -94,7 +94,7 @@ func KeyAuthWithConfig(config KeyAuthConfig) echo.MiddlewareFunc {
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
|
||||
}
|
||||
err, valid := config.Validator(key, c)
|
||||
valid, err := config.Validator(key, c)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if valid {
|
||||
|
@ -15,8 +15,8 @@ func TestKeyAuth(t *testing.T) {
|
||||
res := httptest.NewRecorder()
|
||||
c := e.NewContext(req, res)
|
||||
config := KeyAuthConfig{
|
||||
Validator: func(key string, c echo.Context) (error, bool) {
|
||||
return nil, key == "valid-key"
|
||||
Validator: func(key string, c echo.Context) (bool, error) {
|
||||
return key == "valid-key", nil
|
||||
},
|
||||
}
|
||||
h := KeyAuthWithConfig(config)(func(c echo.Context) error {
|
||||
|
Loading…
Reference in New Issue
Block a user