mirror of
https://github.com/labstack/echo.git
synced 2025-04-21 12:17:04 +02:00
Exposed JWT error
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
7dfec7e641
commit
f2bc6802be
@ -58,7 +58,8 @@ const (
|
|||||||
|
|
||||||
// Errors
|
// Errors
|
||||||
var (
|
var (
|
||||||
ErrJWTInvalid = echo.NewHTTPError(http.StatusBadRequest, "Missing or invalid jwt")
|
ErrJWTMissing = echo.NewHTTPError(http.StatusBadRequest, "Missing or malformed jwt")
|
||||||
|
ErrJWTInvalid = echo.NewHTTPError(http.StatusUnauthorized, "Invalid or expired jwt")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -154,9 +155,11 @@ func JWTWithConfig(config JWTConfig) echo.MiddlewareFunc {
|
|||||||
c.Set(config.ContextKey, token)
|
c.Set(config.ContextKey, token)
|
||||||
return next(c)
|
return next(c)
|
||||||
}
|
}
|
||||||
he := echo.NewHTTPError(http.StatusUnauthorized, "Invalid or expired jwt")
|
return &echo.HTTPError{
|
||||||
he.Inner = err
|
Code: ErrJWTInvalid.Code,
|
||||||
return he
|
Message: ErrJWTInvalid.Message,
|
||||||
|
Inner: err,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,7 +172,7 @@ func jwtFromHeader(header string, authScheme string) jwtExtractor {
|
|||||||
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
|
||||||
}
|
}
|
||||||
return "", ErrJWTInvalid
|
return "", ErrJWTMissing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +181,7 @@ func jwtFromQuery(param string) jwtExtractor {
|
|||||||
return func(c echo.Context) (string, error) {
|
return func(c echo.Context) (string, error) {
|
||||||
token := c.QueryParam(param)
|
token := c.QueryParam(param)
|
||||||
if token == "" {
|
if token == "" {
|
||||||
return "", ErrJWTInvalid
|
return "", ErrJWTMissing
|
||||||
}
|
}
|
||||||
return token, nil
|
return token, nil
|
||||||
}
|
}
|
||||||
@ -189,7 +192,7 @@ func jwtFromCookie(name string) jwtExtractor {
|
|||||||
return func(c echo.Context) (string, error) {
|
return func(c echo.Context) (string, error) {
|
||||||
cookie, err := c.Cookie(name)
|
cookie, err := c.Cookie(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", ErrJWTInvalid
|
return "", ErrJWTMissing
|
||||||
}
|
}
|
||||||
return cookie.Value, nil
|
return cookie.Value, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user