customers
(Fruitful)
October 17, 2023, 3:32am
1
For the past week or possibly even before, we have been encountering an error when attempting to request an access token using a refresh token.
The error message we receive is as follows:
{“reason”:“Invalid Token!”,“error”:“invalid_grant”}
We’re currently uncertain as to when exactly this error began occurring.
As a temporary workaround, we are asking our users to reauthorize our app. While this seems to resolve the issue for the time being, it’s imperative for us to understand the root cause of this problem to ensure it doesn’t persist or recur.
We would greatly appreciate any insights or assistance you can provide regarding this matter.
API Endpoint(s) and/or Zoom API Event(s)
https://zoom.us/oauth/token
Error
{“reason”:“Invalid Token!”,“error”:“invalid_grant”}
chunsiong.zoom
(Chun Siong (tag me for response))
October 17, 2023, 4:52am
2
@customers ,
do you have the code snippet on how you are getting the access token using your refresh token?
customers
(Fruitful)
October 17, 2023, 8:58am
3
@chunsiong.zoom ,
Thank you for your response.
Here is the code:
PHP
// get access token with the refresh token
$basic = base64_encode($Client_ID . ':' . $Client_Secret);
$headers = array(
"Authorization: Basic $basic",
"Content-Type: application/x-www-form-urlencoded"
);
$body = array(
'grant_type' => 'refresh_token',
'refresh_token' => $REFRESH_TOKEN // use stored refresh token.
);
$curl = curl_init("https://zoom.us/oauth/token");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($body));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_ENCODING, "");
curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$arr = json_decode($response, true);
$access_token = $arr['access_token'];
if ($access_token == '') {
http_response_code(400);
echo json_encode(["message" => "Error: $response"]); // Error: {"reason":"Invalid Token!","error":"invalid_grant"}
}
chunsiong.zoom
(Chun Siong (tag me for response))
October 18, 2023, 3:10am
4
@customers ,
I’ve just written this sample, and testing it to be working. There are some slight variations.
$url = 'https://zoom.us/oauth/token';
// Encode the client ID and client secret
$basic = base64_encode($Client_ID . ':' . $Client_Secret);
$headers = [
"Authorization: Basic $basic",
"Content-Type: application/x-www-form-urlencoded"
];
$data = [
'grant_type' => 'refresh_token',
'refresh_token' => $refreshToken,
];
// Encode the data dictionary as x-www-form-urlencoded
$dataEncoded = http_build_query($data);
$options = [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $dataEncoded,
];
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (strpos($httpStatus, '200') !== false) {
$responseJson = json_decode($response, true);
http_response_code(200);
header('Content-Type: application/json');
echo json_encode($responseJson);
//echo $response;
} else {
echo "$httpStatus\n";
}
1 Like