appleboy / gin-jwt

JWT Middleware for Gin framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I get multipart/form-data's token?

2w1nd opened this issue · comments

image
my token in form-data,but TokenLookup seem no support it

	// TokenLookup is a string in the form of "<source>:<name>" that is used
	// to extract token from the request.
	// Optional. Default value "header:Authorization".
	// Possible values:
	// - "header:<name>"
	// - "query:<name>"
	// - "cookie:<name>"
	TokenLookup string

Ha, I just want to raise an issue about this problem. I guess that you have joined the training camp organized by ByteDance also.
I modified a function of the 'auth_jwt.go' file as following to add an option to get token from form data in the request body.

func (mw *GinJWTMiddleware) jwtFromForm(c *gin.Context, key string) (string, error) {
    token := c.PostForm(key)
    if token == "" {return "", ErrEmptyParamToken}
        return token, nil
}
func (mw *GinJWTMiddleware) ParseToken(c *gin.Context) (*jwt.Token, error) {
    for _, method := range methods {
        switch k {
        case "header":   token, err = mw.jwtFromHeader(c, v)
        case "query":    token, err = mw.jwtFromQuery(c, v)
        case "cookie":   token, err = mw.jwtFromCookie(c, v)
        case "param":    token, err = mw.jwtFromParam(c, v)
        case "form":     token, err = mw.jwtFromForm(c, v)
        }
    }
}

yes, you are right, I also participated. I should read the source code carefully😂