PHP & JWT - Basic instructions

Every REST API that uses a JWT may have their own structure for the payload. What is given by the library is just an example of a common format. Zoom tells you what format it needs, so just use that format, regardless of if the issuer parameter being used for the API key vs a URL.

I’ve not tested this exact example myself, but it should go something like:

/* Based on the firebase/php-jwt docs with Zoom's specifications */
use \Firebase\JWT\JWT;

$key = "my api secret here";
$payload = array(
    "iss" => "my api token here",
    "exp" => time()+36000, // expire in 10 hours
);

$jwt = JWT::encode($payload, $key, 'HS256'); // use the secret to sign the payload with a specific hashing algorithim

print_r($jwt); // This is your JWT token. Paste it into https://jwt.io for verification that it is valid. 

/* Now we can talk to Zoom directly using Zoom's PHP example */

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1", //This is the Zoom API endpoint you'd hit to get a list of active users. 
  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 {$jwt}", // You provide your JWT token in the Authorization header. 
    "content-type: application/json"
  ),
));

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

curl_close($curl);

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

Alternatively, if you do not want to use the firebase/php-jwt library, you can generate the token yourself. There’s an example from another user here that works with minimal modification: JWT token creation

2 Likes