From ee2ac3b9a212eb0e94868bad882a69e00b51c23f Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Tue, 3 Jan 2017 20:48:21 -0800 Subject: [PATCH] Key auth validator now accepts context Signed-off-by: Vishal Rana --- middleware/key_auth.go | 4 ++-- middleware/key_auth_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/middleware/key_auth.go b/middleware/key_auth.go index 111d3f39..f2994110 100644 --- a/middleware/key_auth.go +++ b/middleware/key_auth.go @@ -32,7 +32,7 @@ type ( } // KeyAuthValidator defines a function to validate KeyAuth credentials. - KeyAuthValidator func(string) bool + KeyAuthValidator func(string, echo.Context) bool 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()) } - if config.Validator(key) { + if config.Validator(key, c) { return next(c) } diff --git a/middleware/key_auth_test.go b/middleware/key_auth_test.go index 0f0e9762..a88289dd 100644 --- a/middleware/key_auth_test.go +++ b/middleware/key_auth_test.go @@ -15,7 +15,7 @@ func TestKeyAuth(t *testing.T) { res := httptest.NewRecorder() c := e.NewContext(req, res) config := KeyAuthConfig{ - Validator: func(key string) bool { + Validator: func(key string, c echo.Context) bool { return key == "valid-key" }, }