Electron SDK error in function sdkauthCB Status 5

Hi Guys, I trying realize login diferents modes in demo SDK Electron but I have no ideia what’s wrong.

My versions is:

  • Node: v12.0.0
  • Mac Catalina: 10.15.6
  • Electron: 5.0.2

I’m trying to get the demo to go to the login screen, but when I’m on the auth screen and enter the token, the page keeps refreshing in this function:

function sdkauthCB(status) {}

I founded the same error in this topic: Demo keeps refreshing at auth page

In my case follow my example of jwt token:

const jwt = require("jsonwebtoken");
const payloadSDK = {
  appKey: "",
  iat: new Date().getTime() + 5000,
  exp: new Date().getTime() + 5000,
  tokenExp: new Date().getTime(),
};

const tokenSDK = jwt.sign(payloadSDK, "");

console.log(tokenSDK);

My AuthWithJWTToken is returning 0 the same problem peterlzhou having in your topic: Demo keeps refreshing at auth page.

Hi @michael.douglas,

Thanks for the post. Based on the code snippet you provided to generate the JWT token, it seems like the token expiration time(tokenExp) is before the issue time(iat), please follow the instruction here to generate the JWT token: https://github.com/zoom/zoom-sdk-electron/blob/master/CHANGELOG.md#new-sdk-initialization-method-using-jwt-token

Hope this helps. Thanks!

Thanks!

Hi @carson_chen many thanks your help, but I trying your suggestion and I changed my code for this mode:

const jwt = require("jsonwebtoken");

const getIatExp = (dt, minutes) => {
  return {
    iat: new Date(dt.getTime()).getTime(),
    exp: new Date(dt.getTime() + minutes * 60000).getTime(),
  };
};

const getTokenExpire = (iat, minutes) => {
  return {
    tokenExp: new Date(iat + minutes * 60000).getTime(),
  };
};

const { iat, exp } = getIatExp(new Date(), 30);
const { tokenExp } = getTokenExpire(iat, 60);

const payloadSDK = {
  appKey: "",
  iat: iat,
  exp: exp,
  tokenExp: tokenExp,
};

const tokenSDK = jwt.sign(payloadSDK, "");

console.log("\n********* TOKEN ********* \n");
console.log(tokenSDK);
console.log("\n************************* \n");

console.log("\n********* DEBUG ********* \n");
console.log("iat:", new Date(iat).toString());
console.log("exp:", new Date(exp).toString());
console.log("tokenExp:", new Date(tokenExp).toString());
console.log("\n************************* \n");

console.log("\n********* DEBUG PAYLOAD ********* \n");
console.log(payloadSDK);
console.log("\n************************* \n");

console.log("\n********* DEBUG PAYLOAD TO STRING ********* \n");
const debugPayloadSDK = {
  appKey: "",
  iat: new Date(iat).toString(),
  exp: new Date(exp).toString(),
  tokenExp: new Date(tokenExp).toString(),
};
console.log(debugPayloadSDK);
console.log("\n************************* \n");

But I continue received the same error.

My output console log:

********* TOKEN *********

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBLZXkiOiJ5V0lVcVdnT2M2QnRUQjlFblBJOVNUWHc1anpsQVpTNUo0bUUiLCJpYXQiOjE1OTU2MDcxOTEyNzYsImV4cCI6MTU5NTYwODk5MTI3NiwidG9rZW5FeHAiOjE1OTU2MTA3OTEyNzZ9.R0Q7-lKIjjJdaTh_sj4uYuL9VoiPZ4CbMtdqIdgAGYI

************************* 


********* DEBUG ********* 

iat: Fri Jul 24 2020 13:13:11 GMT-0300 (Brasilia Standard Time)
exp: Fri Jul 24 2020 13:43:11 GMT-0300 (Brasilia Standard Time)
tokenExp: Fri Jul 24 2020 14:13:11 GMT-0300 (Brasilia Standard Time)

************************* 


********* DEBUG PAYLOAD ********* 

{ appKey: '',
  iat: 1595607191276,
  exp: 1595608991276,
  tokenExp: 1595610791276 }

************************* 


******* DEBUG PAYLOAD TO STRING ******* 

{ appKey: '',
  iat: 'Fri Jul 24 2020 13:13:11 GMT-0300 (Brasilia Standard Time)',
  exp: 'Fri Jul 24 2020 13:43:11 GMT-0300 (Brasilia Standard Time)',
  tokenExp: 'Fri Jul 24 2020 14:13:11 GMT-0300 (Brasilia Standard Time)' }

*************************

In:

const { tokenExp } = getTokenExpire(iat, 60);

I tried this mode too:

const { tokenExp } = getTokenExpire(iat, 30);

But I continue received the same error code 5.

Sorry @Carson_Chen,

Finally I founded my error :smile:

My first code had errors in TimeStamp.

Now is working, the new code:

const jwt = require("jsonwebtoken");

let dt = new Date();

let data = new Date(dt.getTime() + 30 * 60000).getTime();

let iat = Math.floor(Date.now() / 1000);

let exp = Math.floor(data / 1000);

let tokenExpCreate = new Date(dt.getTime() + 60 * 60000).getTime();

let tokenExp = Math.floor(tokenExpCreate / 1000);

const payloadSDK = {

appKey: "",

iat: iat,

exp: exp,

tokenExp: tokenExp,

};

const tokenSDK = jwt.sign(payloadSDK, "");

console.log("\n********* TOKEN ********* \n");

console.log(tokenSDK);

console.log("\n************************* \n");
1 Like

@michael.douglas Thank you for sharing your findings and glad to hear that the problem has been resolved! Yes, it appears that JavaScript will provide timestamps in milliseconds and the unit of the timestamp in a JWT token should be in second.