Replies: 1 comment
-
You could probably add JWT and KeyAuth middleware in chain and configure JWT not to error out when it sees NB: I have not tested this. func main() {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// add JWT middleware before KeyAuth and configure it continue with next middleware when we see ErrJWTMissing error
e.Use(middleware.JWTWithConfig(middleware.JWTConfig{
ContextKey: "jwtToken",
ContinueOnIgnoredError: true,
ErrorHandlerWithContext: func(err error, c echo.Context) error {
if err == middleware.ErrJWTMissing {
return nil
}
return err
},
}))
e.Use(middleware.KeyAuthWithConfig(middleware.KeyAuthConfig{
KeyLookup: "header:Authorization",
Skipper: func(c echo.Context) bool {
return c.Get("jwtToken") != nil
},
Validator: func(auth string, c echo.Context) (bool, error) {
return auth == "mySuperSecretToken", nil
},
}))
e.GET("/", func(c echo.Context) error {
return c.JSON(http.StatusOK, map[string]string{"msg": "OK"})
})
if err := e.Start(":8080"); err != http.ErrServerClosed {
log.Fatal(err)
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I am looking for how to authenticate my users via echo default middlewares.
I would like to lets say use key based and jwt based authentication in place. If one of them passed, user is allowed to use the resource.
Is it possible to do it without wiring up a custom middleware?
Beta Was this translation helpful? Give feedback.
All reactions