invalid_grant - Authorization code doesn't exist or is invalid for the client

ericabizericabiz Member Posts: 2
edited February 3 in Development

UPDATE: This code doesn't seem to be the issue. I have pulled all other code in the file while figuring this out.

I am getting this error when I have the temporary token and am requesting an access token. I have double-checked that $_GET['code'] has a value and it is the correct value. My client_id and client_secret are also properly set and being passed. This is the code that has an issue:


if (isset($_GET['code']) && (!isset($access_token))) {

// temporary token has been sent by lightspeed -- request access token

$tokenURL = "https://cloud.lightspeedapp.com/oauth/access_token.php";


$postFields = [

  'client_id' => $client_id,

  'client_secret' => $client_secret,

  'code' => $_GET['code'],

  'grant_type' => 'authorization_code'

];


$curl = curl_init();

curl_setopt_array($curl, array(

  CURLOPT_URL => $tokenURL,

  CURLOPT_RETURNTRANSFER => true,

  CURLOPT_ENCODING => "",

  CURLOPT_MAXREDIRS => 10,

  CURLOPT_TIMEOUT => 30,

  CURLOPT_CUSTOMREQUEST => "POST",

  CURLOPT_POSTFIELDS => $postFields

));


$response = curl_exec($curl);

$responseObj = json_decode($response);

$jsonString = json_encode($responseObj, JSON_PRETTY_PRINT);

$err1 = curl_error($curl);


curl_close($curl);


if ($err1) {

 echo "cURL Error (1) #:" . $err;

} else {

echo "<!-- Response " . $response . "-->";

$access_token = $responseObj->access_token;

$_SESSION['access_token'] = $access_token;


echo "<!-- Access token is " . $_SESSION['access_token'] . "-->";


$refresh_token = $responseObj->refresh_token;

$_SESSION['refresh_token'] = $refresh_token;

$authenticated = 1;

}

}

Any help would be appreciated!

Post edited by ericabiz on

1 comment

Sign In or Register to comment.