Vestmore_GO/utils/auth/auth_test.go

35 lines
722 B
Go

package auth
import (
"log"
"testing"
"time"
"github.com/golang-jwt/jwt/v5"
)
type VestMoreClaims struct {
CustomerId int64 `json:"customer_id"`
Version string `json:"version"`
jwt.RegisteredClaims
}
func TestSignTokenAndParseToken(t *testing.T) {
pwdhash := "123131"
vm := &VestMoreClaims{
RegisteredClaims: jwt.RegisteredClaims{
IssuedAt: jwt.NewNumericDate(time.Now()),
ExpiresAt: jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), // 设置过期时间为当前时间加24小时
Issuer: "vermore",
},
}
tstr, err := SignToken(pwdhash, vm)
if err != nil {
panic(err)
}
log.Println(tstr)
vmr := &VestMoreClaims{}
log.Println(ParseToken(tstr, pwdhash, vmr))
log.Println(vmr)
}