# Randomly getting "Signature is invalid" error

**URL:** <https://devforum.zoom.us/t/randomly-getting-signature-is-invalid-error/77667>\
**Category:** Web\
**Tags:** meeting-sdk\
**Created:** [October 20, 2022, 1:11pm UTC](https://devforum.zoom.us/t/randomly-getting-signature-is-invalid-error/77667 "2022-10-20T13:11:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aayush.jain](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@aayush.jain](https://devforum.zoom.us/u/aayush.jain)\
**Post date:** [October 20, 2022, 1:11pm UTC](https://devforum.zoom.us/t/randomly-getting-signature-is-invalid-error/77667/1 "2022-10-20T13:11:33Z")

</div>

**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.

```auto

    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:

```auto

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

```

---

<div class="post-metadata">

**Author:** ![aayush.jain](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@aayush.jain](https://devforum.zoom.us/u/aayush.jain)\
**Post date:** [October 20, 2022, 3:28pm UTC](https://devforum.zoom.us/t/randomly-getting-signature-is-invalid-error/77667/2 "2022-10-20T15:28:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![donte.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/donte.zoom/32/24412_2.png) [@donte.zoom](https://devforum.zoom.us/u/donte.zoom)\
**Post date:** [October 21, 2022, 4:53pm UTC](https://devforum.zoom.us/t/randomly-getting-signature-is-invalid-error/77667/3 "2022-10-21T16:53:43Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![mattmcd](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/mattmcd/32/31750_2.png) [@mattmcd](https://devforum.zoom.us/u/mattmcd)\
**Post date:** [October 21, 2022, 5:29pm UTC](https://devforum.zoom.us/t/randomly-getting-signature-is-invalid-error/77667/4 "2022-10-21T17:29:47Z")

</div>

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 😃

---

<div class="post-metadata">

**Author:** ![donte.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/donte.zoom/32/24412_2.png) [@donte.zoom](https://devforum.zoom.us/u/donte.zoom)\
**Post date:** [October 21, 2022, 11:49pm UTC](https://devforum.zoom.us/t/randomly-getting-signature-is-invalid-error/77667/5 "2022-10-21T23:49:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [November 21, 2022, 9:49am UTC](https://devforum.zoom.us/t/randomly-getting-signature-is-invalid-error/77667/6 "2022-11-21T09:49:57Z")

</div>

Closed on November 21, 2022, 9:49am UTC

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