我正在尝试通过chatkit中的API创建用户。
这是我创建经理的方式:
const chatManager = new ChatManager({
instanceLocator: instanceLocator,
userId: "Irmantas",
tokenProvider: tokenProvider
});
这是我生成JWT令牌的方式:
var oHeader = { alg: 'HS256', typ: 'JWT' };
var oPayload = {};
var tNow = token.KJUR.jws.IntDate.get('now');
var tEnd = token.KJUR.jws.IntDate.get('now + 1day');
oPayload.iss = "api_keys/9e0b93b8-23d6-4ec4-992f-2d7c561a2616:1xhmQyqlYrXa2AYfmrUJfijFJg4Df5cCtQT753fLtuk=";
oPayload.sub = "joh";
oPayload.iat = tNow;
oPayload.exp = tEnd;
oPayload.instance = "9d2504dc-ba0c-43b8-ab5b-70d5c16da851";
oPayload.su = true;
// Sign JWT, password=616161
var sHeader = JSON.stringify(oHeader);
var sPayload = JSON.stringify(oPayload);
var sJWT = token.KJUR.jws.JWS.sign("HS256", sHeader, sPayload, "616161");
但是,当我这样调用API时:
fetch('https://us1.pusherplatform.io/services/chatkit/v3/9d2504dc-ba0c-43b8-ab5b-70d5c16da851/users', {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Authorization': "Bearer " + sJWT
},
body: JSON.stringify({ "name": "Joe", "id": "joe" })
}).then(console.log(sJWT));
我收到一个错误消息,要求进行身份验证。你能帮我发现一个错误吗?