Skip to content

JWT middleware support #36

Open
Open

Description

@basilex

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

Activity

  1. ChadTaljaardt commented on Apr 8, 2018

    @ChadTaljaardt

    I would like this too!

  2. assigned and unassigned on Apr 10, 2018
  3. DarkDrim commented on May 29, 2018

    @DarkDrim

    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))
    
  4. rafgugi commented on Jun 7, 2020

    @rafgugi

    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions