Can someone please provide me PHP code for generating JWTKey

Hello All,

I need php script for generating JWTKey for zoom API v2 integration.
Can someone please provide me the script and their supporting files.

Thank you

1 Like

Hey @Dora_Reddy,

See the JWT Token generation sample PHP code here:

https://marketplace.zoom.us/docs/guides/auth/jwt#sample-code

Thanks,
Tommy

Thanks @tommy for the reply.

From the link i see PHP code below and it is used for Active Users from Zoom not for generateJWT token.

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "authorization: Bearer 39ug3j309t8unvmlmslmlkfw853u8",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Actually I’m expecting script for generating JWT token like below ( I don’t have complete script I found below piece of code in some other thread)

private function generateJWTKey() {
$key = $this->zoom_api_key;
$secret = $this->zoom_api_secret;
$token = array(
“iss” => $key,
“exp” => time() + 3600 //60 seconds as suggested
);
return JWT::encode( $token, $secret );
}

Hey @Dora_Reddy,

Ah true, apologies. You can see sample PHP code and libraries for generating JWT tokens here:

Thanks,
Tommy

1 Like

@tommy I’m facing difficulty in generating JWT token through PHP Code.

So I’m generating JWT token from JWT app provided at marketplace.zoom.us below
https://marketplace.zoom.us/develop/apps/E******************n/credentials

by having Expiration Time for a longer period of 2 years and saving the JWT token in our database.

Later on using the saved JWT token whenever i use Zoom API for creating meetings.

Will this work?

Hey @Dora_Reddy,

That will work, but it is more secure to generate the JWT Token for a shorter amount of time, each time you want to use it.

Did none of the helper libraries work from jwt.io?

Thanks,
Tommy

1 Like

@tommy Thanks for the reply. I looked into https://jwt.io/ but it had many libraries. I’m confused to pick the correct one suitable for my requirement.

In this post Help with api create meeting with php @mike1 posted below code for generating JWT but it didn’t have full code like JWT::encode function. Looking for full working code
//function to generate JWT
private function generateJWTKey() {
$key = $this->zoom_api_key;
$secret = $this->zoom_api_secret;
$token = array(
“iss” => $key,
“exp” => time() + 3600 //60 seconds as suggested
);
return JWT::encode( $token, $secret );
}

1 Like

Did you ever figure this out? I’m just now trying to make this work, but none of the libraries match up well to the Zoom API documentation.

Still i didn’t found any solution. Let me know if you find any. Looking for help.

1 Like

Hey @Dora_Reddy, @laurinkeithdavis,

I would suggest using this library:

Thanks,
Tommy

Yes, that is the one that I’m trying to use, but to no avail.

@laurinkeithdavis Can you provide a sample of how you’re trying to do it?

You can find a well-written write up here as well: https://www.sitepoint.com/php-authorization-jwt-json-web-tokens/

1 Like

I don’t know that posting any example I have so far would be helpful. I’m just trying to make the connection, I can’t even figure out what the parameters are supposed to be or how I generate the token.

Read that one as well, and thanks, but still can’t figure it out. Is there not a working example of using the Zoom API in PHP? The one in the docs does not make sense (https://marketplace.zoom.us/docs/guides/auth/jwt) - what goes where in that sample?? What is the “Bearer”?

@laurinkeithdavis, I found the Zoom documentation lacking as well. Here’s an example of generating the token with firebase/php-jwt and GuzzleHttp (see code below).

This will generate a JWT token with a 5 second lifespan. Then, it will use the token to make a request to Zoom’s API with GuzzleHttp and list users on the account.

$api_secret = “XXXXXX”;
$api_key = “XXXXXX”;
$payload = array(
“iss” => $api_key,
“exp” => (time() + 5)
);
$jwt = JWT::encode($payload, $api_secret);

$client = new \GuzzleHttp\Client([‘headers’ => [‘authorization’ => 'Bearer '.$jwt]]);
$response = $client->request(
‘GET’,
https://api.zoom.us/v2/users
);

return json_decode($response->getBody(), true);

2 Likes

Thanks for providing a solution @andrew4! :slight_smile:

@laurinkeithdavis let me know if this helps!

As for what the “Bearer” is, that just let’s the Zoom API know what kind of authentication to expect. Here is the request header you want to provide when making requests to the Zoom API:

{ "Authorization": "Bearer JWT_TOKEN_HERE" }

We will work on improving our JWT docs as soon as possible.

-Tommy

1 Like