diff --git a/jwt/jwt.go b/jwt/jwt.go index 73cac97..f1fdfbe 100644 --- a/jwt/jwt.go +++ b/jwt/jwt.go @@ -2,13 +2,15 @@ package jwt import ( "bytes" + "errors" + jwt_lib "github.com/dgrijalva/jwt-go" "github.com/gin-gonic/gin" ) func Auth(secret string) gin.HandlerFunc { return func(c *gin.Context) { - _, err := jwt_lib.ParseFromRequest(c.Request, func(token *jwt_lib.Token) (interface{}, error) { + token, err := jwt_lib.ParseFromRequest(c.Request, func(token *jwt_lib.Token) (interface{}, error) { var b bytes.Buffer b.Write([]byte(secret)) return b, nil @@ -17,5 +19,8 @@ func Auth(secret string) gin.HandlerFunc { if err != nil { c.Fail(401, err) } + if !token.Valid { + c.Fail(401, errors.New("Invalid Token")) + } } }