admin管理员组

文章数量:1295625

Further to my post Xero api connection

I've created a very simple test code based on / The code opens to the xero permissions page correctly but when it returns (with a url containing all necessary parts) I just get an error response of "invalid_client" from the api.

The client id is correct code and url string being returned so I'm not sure why it's not validating and returning my tokens ??

My Code:

 <?php
session_start();

$clientId='BFFD3*************B848C70';
$redirectUri='http://localhost/starter/beta.php';
$state = 'abc1';
$codeVerifier = 'RgdEXOZqF4lUQ8KcYJps7eY0zd3OsPQQOwVDdl86e3';  

// callback from xero 
if($_GET['code'] && $state == $_GET['state']){


$session_state = $_GET['session_state'];
$state = $_GET['state'];
$code  = $_GET['code'];
$scope  = $_GET['scope'];
 

// Token endpoint URL
$tokenUrl = '';
 

// cURL options
$ch = curl_init($tokenUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
    'grant_type' => 'authorization_code',
    'client_id' => $clientId,
    'code' => $code,
    'redirect_uri'=>$redirectUri,
   'code_verifier' =>$codeVerifier
]));

// Execute the request
$response = curl_exec($ch);

if(curl_error($ch)) {
    var_dump(curl_error($ch));
}


curl_close($ch);

print_r($response);
exit();

 
} else {
    
 // initial auth 
// opens page to authorise permission
// workign as expected 

    $codeChallenge = base64url_encode(hash('sha256', $codeVerifier, true)); 

$url = ";client_id=$clientId&redirect_uri=$redirectUri&scope=openid profile email accounting.transactions&state=$state&code_challenge=$codeChallenge&code_challenge_method=S256";

header("Location:$url"); 

exit(); 

}

本文标签: phpXero API PKCE giving Invalidclient errorStack Overflow