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

25 lines
640 B
Go
Raw Normal View History

2023-02-09 14:40:49 +08:00
package tokenverify
2022-10-27 11:45:42 +08:00
import (
2023-06-14 12:23:51 +08:00
"testing"
2023-06-11 16:52:01 +08:00
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/golang-jwt/jwt/v4"
2022-10-27 11:45:42 +08:00
)
func Test_ParseToken(t *testing.T) {
2023-06-11 16:52:01 +08:00
config.Config.TokenPolicy.AccessSecret = "OpenIM_server"
2023-06-14 12:23:51 +08:00
claims1 := BuildClaims("123456", constant.AndroidPadPlatformID, 10)
2023-06-11 16:52:01 +08:00
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims1)
tokenString, err := token.SignedString([]byte(config.Config.TokenPolicy.AccessSecret))
if err != nil {
t.Fatal(err)
}
claim2, err := GetClaimFromToken(tokenString)
if err != nil {
t.Fatal(err)
}
t.Log(claim2)
2022-10-27 11:45:42 +08:00
}