1

I am trying to create users though the API in chatkit.

Here is how I create the manager:

    const chatManager = new ChatManager({
        instanceLocator: instanceLocator,
        userId: "Irmantas",
        tokenProvider: tokenProvider
    });

Here is how I generate the JWT token:

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");

However, when I call the API like this:

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));

I get an error that authentication is required. Could you help me find a mistake?

isherwood
  • 58,414
  • 16
  • 114
  • 157
Irmantas Želionis
  • 2,194
  • 3
  • 17
  • 30
  • What does `sJWT` evaluate to just prior to the request? – isherwood Apr 01 '19 at 13:26
  • eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhcGlfa2V5cy85ZTBiOTNiOC0yM2Q2LTRlYzQtOTkyZi0yZDdjNTYxYTI2MTY6MXhobVF5cWxZclhhMkFZZm1yVUpmaWpGSmc0RGY1Y0N0UVQ3NTNmTHR1az0iLCJzdWIiOiJJcm1hbnRhcyIsImlhdCI6MTU1NDEyNTM4MSwiZXhwIjoxNTU0MjExNzgxLCJpbnN0YW5jZSI6IjlkMjUwNGRjLWJhMGMtNDNiOC1hYjViLTcwZDVjMTZkYTg1MSIsInN1Ijp0cnVlfQ.S8t5gFNA_7L8ZMg_8EzqlxtaGNqto1QGp89Tu0-fJTI – Irmantas Želionis Apr 01 '19 at 13:30

0 Answers0