1
0
mirror of https://github.com/labstack/echo.git synced 2025-06-06 23:46:16 +02:00

Key auth validator now accepts context

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2017-01-03 20:48:21 -08:00
parent 97c680662d
commit ee2ac3b9a2
2 changed files with 3 additions and 3 deletions

View File

@ -32,7 +32,7 @@ type (
} }
// KeyAuthValidator defines a function to validate KeyAuth credentials. // KeyAuthValidator defines a function to validate KeyAuth credentials.
KeyAuthValidator func(string) bool KeyAuthValidator func(string, echo.Context) bool
keyExtractor func(echo.Context) (string, error) keyExtractor func(echo.Context) (string, error)
) )
@ -94,7 +94,7 @@ func KeyAuthWithConfig(config KeyAuthConfig) echo.MiddlewareFunc {
if err != nil { if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error()) return echo.NewHTTPError(http.StatusBadRequest, err.Error())
} }
if config.Validator(key) { if config.Validator(key, c) {
return next(c) return next(c)
} }

View File

@ -15,7 +15,7 @@ func TestKeyAuth(t *testing.T) {
res := httptest.NewRecorder() res := httptest.NewRecorder()
c := e.NewContext(req, res) c := e.NewContext(req, res)
config := KeyAuthConfig{ config := KeyAuthConfig{
Validator: func(key string) bool { Validator: func(key string, c echo.Context) bool {
return key == "valid-key" return key == "valid-key"
}, },
} }