You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
570 B
24 lines
570 B
package tools
|
|
|
|
import (
|
|
"github.com/golang-jwt/jwt"
|
|
)
|
|
|
|
const SECRET = "taoshihan"
|
|
|
|
func MakeToken(obj map[string]interface{}) (string, error) {
|
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims(obj))
|
|
tokenString, err := token.SignedString([]byte(SECRET))
|
|
return tokenString, err
|
|
}
|
|
func ParseToken(tokenStr string) map[string]interface{} {
|
|
token, err := jwt.Parse(tokenStr, func(token *jwt.Token) (i interface{}, e error) {
|
|
return []byte(SECRET), nil
|
|
})
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
finToken := token.Claims.(jwt.MapClaims)
|
|
return finToken
|
|
}
|