diff options
author | Wim <wim@42.be> | 2021-03-20 22:40:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-20 22:40:23 +0100 |
commit | ee5d9b43b54a3becf3cb4025198f24608d35500d (patch) | |
tree | dd3614db7423da52f5a71da3001e48d1e4195ea1 /vendor/github.com/labstack/echo/v4/middleware/jwt.go | |
parent | 3a8857c8c9efb2c67fb8c175f31d2b9c617b771b (diff) | |
download | matterbridge-msglm-ee5d9b43b54a3becf3cb4025198f24608d35500d.tar.gz matterbridge-msglm-ee5d9b43b54a3becf3cb4025198f24608d35500d.tar.bz2 matterbridge-msglm-ee5d9b43b54a3becf3cb4025198f24608d35500d.zip |
Update vendor (#1414)
Diffstat (limited to 'vendor/github.com/labstack/echo/v4/middleware/jwt.go')
-rw-r--r-- | vendor/github.com/labstack/echo/v4/middleware/jwt.go | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/vendor/github.com/labstack/echo/v4/middleware/jwt.go b/vendor/github.com/labstack/echo/v4/middleware/jwt.go index 3c7c4868..da00ea56 100644 --- a/vendor/github.com/labstack/echo/v4/middleware/jwt.go +++ b/vendor/github.com/labstack/echo/v4/middleware/jwt.go @@ -57,6 +57,7 @@ type ( // - "query:<name>" // - "param:<name>" // - "cookie:<name>" + // - "form:<name>" TokenLookup string // AuthScheme to be used in the Authorization header. @@ -86,6 +87,7 @@ const ( // Errors var ( ErrJWTMissing = echo.NewHTTPError(http.StatusBadRequest, "missing or malformed jwt") + ErrJWTInvalid = echo.NewHTTPError(http.StatusUnauthorized, "invalid or expired jwt") ) var ( @@ -166,6 +168,8 @@ func JWTWithConfig(config JWTConfig) echo.MiddlewareFunc { extractor = jwtFromParam(parts[1]) case "cookie": extractor = jwtFromCookie(parts[1]) + case "form": + extractor = jwtFromForm(parts[1]) } return func(next echo.HandlerFunc) echo.HandlerFunc { @@ -213,8 +217,8 @@ func JWTWithConfig(config JWTConfig) echo.MiddlewareFunc { return config.ErrorHandlerWithContext(err, c) } return &echo.HTTPError{ - Code: http.StatusUnauthorized, - Message: "invalid or expired jwt", + Code: ErrJWTInvalid.Code, + Message: ErrJWTInvalid.Message, Internal: err, } } @@ -265,3 +269,14 @@ func jwtFromCookie(name string) jwtExtractor { return cookie.Value, nil } } + +// jwtFromForm returns a `jwtExtractor` that extracts token from the form field. +func jwtFromForm(name string) jwtExtractor { + return func(c echo.Context) (string, error) { + field := c.FormValue(name) + if field == "" { + return "", ErrJWTMissing + } + return field, nil + } +} |