mirror of
https://github.com/labstack/echo.git
synced 2025-03-23 21:29:26 +02:00
Fixed key auth middleware
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
ff27cfaab3
commit
97c680662d
@ -107,15 +107,17 @@ func KeyAuthWithConfig(config KeyAuthConfig) echo.MiddlewareFunc {
|
|||||||
func keyFromHeader(header string, authScheme string) keyExtractor {
|
func keyFromHeader(header string, authScheme string) keyExtractor {
|
||||||
return func(c echo.Context) (string, error) {
|
return func(c echo.Context) (string, error) {
|
||||||
auth := c.Request().Header.Get(header)
|
auth := c.Request().Header.Get(header)
|
||||||
|
if auth == "" {
|
||||||
|
return "", errors.New("Missing key in request header")
|
||||||
|
}
|
||||||
if header == echo.HeaderAuthorization {
|
if header == echo.HeaderAuthorization {
|
||||||
l := len(authScheme)
|
l := len(authScheme)
|
||||||
if len(auth) > l+1 && auth[:l] == authScheme {
|
if len(auth) > l+1 && auth[:l] == authScheme {
|
||||||
return auth[l+1:], nil
|
return auth[l+1:], nil
|
||||||
}
|
}
|
||||||
} else {
|
return "", errors.New("Invalid key in request header")
|
||||||
return auth, nil
|
|
||||||
}
|
}
|
||||||
return "", errors.New("Missing or invalid key in request header")
|
return auth, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user