Randomly getting "Signature is invalid" error

Meeting SDK Type and Version
@zoomus/websdk: 2.8.0
Type: Component View

Description
Randomly getting “Signature is invalid” error while joining zoom meeting. But when I retries to join zoom meeting with same signature then after some retries or some time I can able to join with the same signature.

I am generating signature at the server side with role = 0.

Error?
{type: ‘JOIN_MEETING_FAILED’, reason: ‘Signature is invalid.’, errorCode: 3712}

Following is the signature generation code snippet.


    private JSONObject tokenHeader = new JSONObject()
            .put("alg", "HS256")
            .put("typ", "JWT");

    public String generateSignature(String meetingId, int role) {
        long currentTimestamp = Math.round(System.currentTimeMillis()/1000);
        long tokenExpiryTime = currentTimestamp + zoomSDKJWTTokenExpiryInHr * 60 * 60;
        JSONObject payload = new JSONObject()
                .put("sdkKey", zoomSDKKey)
                .put("mn", meetingId)
                .put("role", role)
                .put("iat", currentTimestamp)
                .put("exp", tokenExpiryTime)
                .put("appKey", zoomSDKKey)
                .put("tokenExp", tokenExpiryTime);

        try {
            Algorithm algorithm = Algorithm.HMAC256(zoomSDKSecret);
            String signature = JWT.create()
                    .withHeader(tokenHeader.toMap())
                    .withPayload(payload.toMap())
                    .sign(algorithm);

            return signature;
        } catch (JWTCreationException exception){
            throw new RuntimeException("unable to generate signature");
        }
    }

Following is the typescript code snippet to join meeting:


  const clientInit = (): typeof EmbeddedClient | undefined => {

    if(!containerRef.current) {
      return;
    }

    const _client: typeof EmbeddedClient = ZoomMtgEmbedded.createClient();

    _client.init({
      debug: false,
      zoomAppRoot: containerRef.current,
      language: 'en-US',
      customize: {
        activeApps: {
          popper: undefined
        },
        meetingInfo: [],
        video: {
          isResizable: true
        }
      },
      
    })
    .catch((err: any) => {
      console.error("unable to init zoom client", err);
    })

    setClient(_client);
    return _client;
  }

  const clientJoin = (_client?: typeof EmbeddedClient) => {

    if(!_client) {
      console.error("client not found");
      return ;
    }

    console.info("joining client");
    _client.join({
    	sdkKey: zoomConnectionData.sdkKey,
    	signature: zoomConnectionData.signature,
    	meetingNumber: zoomConnectionData.meetingNumber,
    	password: zoomConnectionData.password,
    	userName: currentUser.name,
      userEmail: currentUser.email,
      success: handleClientJoined,
      error: handleErrorOnJoin
    })
    .then((res) => {
      handleClientJoined();
    })
    .catch((err) => {
      handleErrorOnJoin(err);
    })
  }

Found that Math.round() returning a timestamp which is randomly 10-30sec more with actual value.
After removing it, things started working fine.

1 Like

@aayush.jain,

Thank you for sharing the root cause of the behavior you were seeing. We appreciate your contribution to the developer forum as this information will be helpful to other community members facing the same problem.

1 Like

Donte, thanks for pointing me in this direction! This must have been the cause of the issue on our end too, as prior we were using Math round in our Java servlet. All is working fine now after removing that :smiley:

1 Like

You are welcome @mattmcd! Much gratitude to @aayush.jain for posting his solution – we appreciate your contributions to the Zoom Developer Forum.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.