Kaseya Community

Authenticating with the rest api using PHP & cURL

This question is answered

Hi All,

I'm hoping someone can help spot where I am going wrong.

I am trying to authenticate with our kaseya rest api using php and curl code, below is how I have setup the encryption and create the auth string as per the kaseya documentation.

$RawSHA256Hash = hash("sha256", $password);

$CoveredSHA256HashTemp = hash('sha256',$password.$username);

$CoveredSHA256Hash = hash('sha256',$CoveredSHA256HashTemp.$random);

$RawSHA1Hash = hash('sha1',$password);

$CoveredSHA1HashTemp = hash('sha1',$password.$username);

$CoveredSHA1Hash = hash('sha1',$CoveredSHA1HashTemp.$random);

$auth = join(
',', [
'user=' . $username,
'pass2=' . $CoveredSHA256Hash,
'pass1=' . $CoveredSHA1Hash,
'rpass2=' . $RawSHA256Hash,
'rpass1=' . $RawSHA1Hash,
'rand2=' . $random,

]);

echo "$auth";
}

Below is the PHP curl setup I have to retrieve the bearer token I should get back  :

include '/var/www/translator/html/functions/kasauth.php';

$vsa = "https://kasurl/api/v1.0/auth";


$ch = curl_init();

$headers = array (

'Content-Type: application/json',
'Authorization: Basic ' . base64_encode("kasauth()")
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_URL, $vsa);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


$output = curl_exec($ch);

if($output === FALSE) {

echo "cURL Error: " . curl_error($ch);

}

curl_close($ch);

print_r($output);

However all I get back is this error now : { "ResponseCode": 4000010, "Status": "Failed", "Error": "Auth header missing user param" }

If I add the username to the custom header I setup I still get the same error returned.  I'm pretty sure from the error I'm getting that the issue lies with my header.

I'm new to coding and have not been able to figure this out. Is anyone able to assist?

Regards, 

 

Verified Answer
  • Hi,

    This was a password issue preventing this from working. There was no issue with the code above.

    Regards,

All Replies
  • Hi,

    This was a password issue preventing this from working. There was no issue with the code above.

    Regards,