1
0
mirror of https://github.com/labstack/echo.git synced 2025-03-19 21:17:58 +02:00

Fixed key auth middleware

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2017-01-02 23:09:46 -08:00
parent ff27cfaab3
commit 97c680662d

View File

@ -107,15 +107,17 @@ func KeyAuthWithConfig(config KeyAuthConfig) echo.MiddlewareFunc {
func keyFromHeader(header string, authScheme string) keyExtractor {
return func(c echo.Context) (string, error) {
auth := c.Request().Header.Get(header)
if auth == "" {
return "", errors.New("Missing key in request header")
}
if header == echo.HeaderAuthorization {
l := len(authScheme)
if len(auth) > l+1 && auth[:l] == authScheme {
return auth[l+1:], nil
}
} else {
return auth, nil
return "", errors.New("Invalid key in request header")
}
return "", errors.New("Missing or invalid key in request header")
return auth, nil
}
}