Skip to content

Commit

Permalink
Add an option to parse token from POST form data.
Browse files Browse the repository at this point in the history
  • Loading branch information
Starballoon committed May 25, 2022
1 parent 687525f commit b4eaf1c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions auth_jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,16 @@ func (mw *GinJWTMiddleware) jwtFromParam(c *gin.Context, key string) (string, er
return token, nil
}

func (mw *GinJWTMiddleware) jwtFromForm(c *gin.Context, key string) (string, error) {
token := c.PostForm(key)

if token == "" {
return "", ErrEmptyParamToken
}

return token, nil
}

// ParseToken parse jwt token from gin context
func (mw *GinJWTMiddleware) ParseToken(c *gin.Context) (*jwt.Token, error) {
var token string
Expand All @@ -733,6 +743,8 @@ func (mw *GinJWTMiddleware) ParseToken(c *gin.Context) (*jwt.Token, error) {
token, err = mw.jwtFromCookie(c, v)
case "param":
token, err = mw.jwtFromParam(c, v)
case "form":
token, err = mw.jwtFromForm(c, v)
}
}

Expand Down

0 comments on commit b4eaf1c

Please sign in to comment.