How do I generate a valid SDK signature from PHP?

Hi, I’m trying to generate a signature but I’m only getting an error.

function generate_signature ( $api_key, $api_secret, $meeting_number, $role){
    //Set the timezone to UTC
    date_default_timezone_set("UTC");
      $time = time() * 1000 - 30000;//time in milliseconds (or close enough)
      $data = base64_encode($api_key . $meeting_number . $time . $role);
      $hash = hash_hmac('sha256', $data, $api_secret, true);
      $_sig = $api_key . "." . $meeting_number . "." . $time . "." . $role . "." . base64_encode($hash);
      //return signature, url safe base64 encoded
      return rtrim(strtr(base64_encode($_sig), '+/', '-_'), '=');
}
{type: 'JOIN_MEETING_FAILED', reason: 'Signature is invalid.', errorCode: 3712}

I’m using the CDN

<!-- For ZOOM Component and Client View -->
    <script src="https://source.zoom.us/2.4.5/lib/vendor/react.min.js"></script>
    <script src="https://source.zoom.us/2.4.5/lib/vendor/react-dom.min.js"></script>
    <script src="https://source.zoom.us/2.4.5/lib/vendor/redux.min.js"></script>
    <script src="https://source.zoom.us/2.4.5/lib/vendor/redux-thunk.min.js"></script>
    <script src="https://source.zoom.us/2.4.5/lib/vendor/lodash.min.js"></script>
    
    <!-- For ZOOM Component View -->
    <script src="https://source.zoom.us/2.4.5/zoom-meeting-embedded-2.4.5.min.js"></script>
let meetingSDKElement = document.getElementById('meetingSDKElement')

client.init({
    debug: true,
    zoomAppRoot: meetingSDKElement,
    language: 'en-US',
    customize: {
        meetingInfo: [
            'topic',
            'host',
            'mn',
            'pwd',
            'telPwd',
            'invite',
            'participant',
            'dc',
            'enctype',
        ],
        toolbar: {
            buttons: [{
                text: 'Custom Button',
                className: 'CustomButton',
                onClick: () => {
                    console.log('custom button')
                }
            }]
        }
    }
});

client.join({
    sdkKey: SDKKEY,
    signature: SIGNATURE,
    meetingNumber: MEETINGNUMBER,
    password: ZOOMPASSWORD,
    userName: ZOOMUSER,
});

Did you find the solution? Stuck at a similar problem.

Hi, @SVIF,

Welcome to the Zoom Developer Forum – we are thrilled to have you join the community. Would you be able to share what App type you are using to generate the meeting signature? The first thing I would recommend is to manually generate and enter the signature. This will help isolate the root cause of the behavior you are seeing.

Best,
Donte

Hi, I dropped this for a while but would now like to have a solution.
Can you provide me with the necessary code to generate a valid SDK Signature in PHP? I’m using a Meeting SDK for the web.

@SVIF Here is example SDK Signature in PHP:


<?php

/**
 * Below are the fields required for the JWT payload

 * sdkKey: Your SDK Key. Required for Web, optional for Native.
 * sdkSecret Required, your SDK API Secret
 * mn: The Zoom Meeting or Webinar Number. Required for Web, optional for Native.
 * role: The user role. Required for Web, optional for Native. Values: 0 to specify participant, 1 to specify host.
 * iat: The current timestamp in epoch format. Required.
 * exp: JWT expiration date. Required. Values: Min = 1800 seconds greater than iat value, max = 48 hours greater than iat value. In epoch format.
 * tokenExp: JWT expiration date. Required. Values: Min = 1800 seconds greater than iat value, max = 48 hours greater than iat value. In epoch format.
 * 
 * Source: https://marketplace.zoom.us/docs/sdk/native-sdks/auth/
 */
function generateSignature($sdkKey, $sdkSecret, $meetingNumber, $role) {
    $iat = time();
    $exp = $iat + 60 * 60 * 2;
    $token_payload = [
    
        'sdkKey' => $sdkKey,
        'mn' => $meetingNumber,
        'role' => $role,
        'iat' => $iat,
        'exp' => $exp,
        'tokenExp' => $exp
    ];

    $jwt = JWT::encode($token_payload, $sdkSecret, 'HS256');
    
    return $jwt;
}

echo(generateSignature($_ENV['SDK_KEY'], $_ENV['SDK_SECRET'], 12345678912, 0));
1 Like

i have same problem with C# i try to use SDK Key and Secrets And try to use Jwt apiKey And secrets and have same problem why dot end this we need to solve this
??

@eelsayyad,

Thanks for posting in the Zoom Developer Forum. Can you confirm you if are using the SDK Key and Secrets from Meeting SDK Marketplace App type? Here is a link to the help documentation for reference :

In the meantime, you may also find this thread which includes C# code snippet helpful: