JWTTokenAdapter is a `echo` middleware, by rewriting the header, the jwt token support header "Authorization: {token}" and "Authorization: Bearer {token}".
()
| 205 | // JWTTokenAdapter is a `echo` middleware, by rewriting the header, the jwt token support header |
| 206 | // "Authorization: {token}" and "Authorization: Bearer {token}". |
| 207 | func JWTTokenAdapter() echo.MiddlewareFunc { |
| 208 | return func(next echo.HandlerFunc) echo.HandlerFunc { |
| 209 | return func(c echo.Context) error { |
| 210 | auth := c.Request().Header.Get(echo.HeaderAuthorization) |
| 211 | if auth != "" && !strings.HasPrefix(auth, middleware.DefaultJWTConfig.AuthScheme) { |
| 212 | c.Request().Header.Set(echo.HeaderAuthorization, |
| 213 | fmt.Sprintf("%s %s", middleware.DefaultJWTConfig.AuthScheme, auth)) |
| 214 | } |
| 215 | return next(c) |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | func AuthFilter() echo.MiddlewareFunc { |
| 221 | return func(next echo.HandlerFunc) echo.HandlerFunc { |
no test coverage detected