Skip to content

JWT middleware support #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
basilex opened this issue Nov 27, 2017 · 3 comments
Open

JWT middleware support #36

basilex opened this issue Nov 27, 2017 · 3 comments

Comments

@basilex
Copy link

basilex commented Nov 27, 2017

It whould be nice to have an implementation of JWT auth middleware like an existing basic auth.
Thanx!

@ChadTaljaardt
Copy link

I would like this too!

@buaazp buaazp assigned buaazp and unassigned buaazp Apr 10, 2018
@DarkDrim
Copy link

DarkDrim commented May 29, 2018

Example of auth middleware for fasthttp & fasthttprouter

type Middleware func(h fasthttp.RequestHandler) fasthttp.RequestHandler
type AuthFunc func(ctx *fasthttp.RequestCtx) bool
func NewAuthMiddleware(authFunc AuthFunc) Middleware {
    return func(h fasthttp.RequestHandler) fasthttp.RequestHandler {
        return func(ctx *fasthttp.RequestCtx) {
            result, err := authFunc(ctx)
            if result {
                h(ctx)
            } else {
                ctx.Response.SetStatusCode(fasthttp.StatusUnauthorized)
            }
        }
    }
}

func AuthCheck(ctx *fasthttp.RequestCtx) (bool, error) {
    return false; // for example ;)
}

// router
authMiddleware := middleware.NewAuthMiddleware(security.AuthCheck)
...
router.GET("/protected", authMiddleware(handlers.ProtectedHandler))

@rafgugi
Copy link

rafgugi commented Jun 7, 2020

i think middleware should not too coupled in the router. you should implement your middleware in your appliaction yourself because it depends on how the security of your appliaction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants