Annual upgrade 3.8.5 to 4.0.7 and now invalid signature

I upgrade Meeting-SDK Web Client view once a year and today began the upgrade from 3.8.5 to 4.0.7.

I have some programming knowledge but only a limited amount. For each annual update we would get our host to run $ git clone GitHub - zoom/meetingsdk-web-sample: Zoom Meeting SDK web sample and then amend index.js so that it included the ID and Secret (initially it was API_KEY, then SDK_KEY and last year CLIENT_ID)

index.js then contained:

  var signature = ZoomMtg.generateSDKSignature({
    meetingNumber: meetingConfig.mn,
    sdkKey: CLIENT_ID,
    sdkSecret: CLIENT_SECRET,
    role: meetingConfig.role,
    success: function (res) {
      console.log(res);
      meetingConfig.signature = res;
      meetingConfig.sdkKey = CLIENT_ID;
      var joinUrl = "/meeting.html?" + testTool.serialize(meetingConfig);
      console.log(joinUrl);
      window.open(joinUrl, "_blank");
    },
  });

but since version 3.12.0 generateSDKSignature has been removed/deprecated.

Is there some alternative code I can use in index.js to generate the signature?

As a quick update, I have now found GitHub - zoom/meetingsdk-auth-endpoint-sample: Generate a Meeting SDK JWT to join Zoom meetings and webinars with the Meeting SDK. and I am hoping that, once it is installed and .env edited I will be able to replace the above code with the something else although not sure what it will look like yet. Fingers crossed.

Problem is now solved. In root directory meeting.html add in

<script language="JavaScript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsrsasign/8.0.20/jsrsasign-all-min.js"></script>

In index.js then change the getSignature function to:

async function getSignature(meetingNumber, role) {
try {
const iat = Math.round(new Date().getTime() / 1000) - 30;
const exp = iat + 60 * 60 * 2;
const oHeader = { alg: ‘HS256’, typ: ‘JWT’ };
const oPayload = {
appKey: CLIENT_ID,
sdkKey: CLIENT_ID,
iat: iat, //token issue timestamp
exp: exp, //JWT token expiry timestamp, at least 1800 seconds greater than iat
mn: meetingNumber,
role: role, //0 is participant, 1 is host
tokenExp: exp, //SDK authenticated token expire timestamp
video_webrtc_mode: 0 //optional and web only
};
const sHeader = JSON.stringify(oHeader);
const sPayload = JSON.stringify(oPayload);
const signature = KJUR.jws.JWS.sign(‘HS256’, sHeader, sPayload, CLIENT_SECRET);
// console.log(signature);
return signature;
} catch (error) {
console.log(error);
throw error;
}
}