First day in production. First authentication was successful; second failed returning 400 and the following error
{ "error" : "invalid_grant", "errors" : [ { "errorCode" : "OAU-106", "message" : "Invalid authorization code" } ], "error_description" : "Invalid authorization code" }
during the last leg of Code Flow Authentication when the code is exchanged for a pair of tokens.
I am using PHP and cURL.
Interesting that the code works randomly. 1 out of 10 attempts succeed.
I also noticed that expires_in parameter is not included when authorization code is passed to my callback as documentation suggests ( https://developer.ringcentral.com/api-docs/latest/index.html#!#AuthorizationFlows.html)
Desperately need help.
Here is my code
$req=' https://platform.ringcentral.com/restapi/oauth/token';
$post = array (
'grant_type' => 'authorization_code',
'code' => $code , 'redirect_uri' => ' https://xxxxxxxx.io/rc/query.php');
$ch = curl_init($req);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0 Y/2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$apiKey = base64_encode($APPKEY);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Basic ' . $apiKey,
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
$r=json_decode($response, true);
{ "error" : "invalid_grant", "errors" : [ { "errorCode" : "OAU-106", "message" : "Invalid authorization code" } ], "error_description" : "Invalid authorization code" }
during the last leg of Code Flow Authentication when the code is exchanged for a pair of tokens.
I am using PHP and cURL.
Interesting that the code works randomly. 1 out of 10 attempts succeed.
I also noticed that expires_in parameter is not included when authorization code is passed to my callback as documentation suggests ( https://developer.ringcentral.com/api-docs/latest/index.html#!#AuthorizationFlows.html)
Desperately need help.
Here is my code
$req=' https://platform.ringcentral.com/restapi/oauth/token';
$post = array (
'grant_type' => 'authorization_code',
'code' => $code , 'redirect_uri' => ' https://xxxxxxxx.io/rc/query.php');
$ch = curl_init($req);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0 Y/2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$apiKey = base64_encode($APPKEY);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Basic ' . $apiKey,
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
$r=json_decode($response, true);