-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Description
Would be nice if the JWT middleware had a configuration option Required bool (or maybe an inverse variant for backwards compatibility, can't think of a name)?
Use-case is when you do not want a route to require a JWT, but display different behavior if a JWT is there.
Example:
func restricted(c echo.Context) error {
user := c.Get("user")
if user != nil {
claims := user.(*jwt.Token).Claims.(*jwtCustomClaims)
name := claims.Name
return c.String(http.StatusOK, "Welcome "+name+"!")
} else {
return c.String(http.StatusOK, "Welcome anonymous!")
}
}
Currently this would throw a ErrJWTMissing
https://github.com/labstack/echo/blob/master/middleware/jwt.go#L142
and
https://github.com/labstack/echo/blob/master/middleware/jwt.go#L158
Which would be the expected behavior if Required is true.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels