20 lines
369 B
Go
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)
|
|
}
|
|
}
|
|
}
|