hanayo/vendor/github.com/johnniedoe/contrib/jwt/jwt.go
2019-02-23 13:29:15 +00:00

20 lines
369 B
Go

package jwt
import (
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) {
b := ([]byte(secret))
return b, nil
})
if err != nil {
c.AbortWithError(401, err)
}
}
}