Files
open-im-server/pkg/common/tokenverify/jwt_token_test.go
T

25 lines
604 B
Go
Raw Normal View History

2023-06-30 09:45:02 +08:00
package tokenverify
import (
"testing"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/golang-jwt/jwt/v4"
)
func Test_ParseToken(t *testing.T) {
2023-06-30 23:04:28 +08:00
config.Config.Secret = "OpenIM_server"
2023-06-30 09:45:02 +08:00
claims1 := BuildClaims("123456", constant.AndroidPadPlatformID, 10)
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims1)
2023-06-30 23:04:28 +08:00
tokenString, err := token.SignedString([]byte(config.Config.Secret))
2023-06-30 09:45:02 +08:00
if err != nil {
t.Fatal(err)
}
claim2, err := GetClaimFromToken(tokenString)
if err != nil {
t.Fatal(err)
}
t.Log(claim2)
}