Start a Conversation

This post is more than 5 years old

Solved!

Go to Solution

4111

November 29th, 2017 16:00

REST API Auth with PHP

I'm hoping to see if I can get some guidance on how to auth against appsync with PHP. After reading through the documentation, and tearing apart what I saw from another post in powershell I wrote up a simple script in php- however when I attempt to complete the auth it returns the following message:

starting...

CAS is Unavailable

There was an error trying to complete your request. Please notify your support desk or try again.

done!

The "starting..." and "done!" are just echo'd statically for my sanity. Not sure where to debug as this is within CAS, within Appsync so any help would be great!

The code is as follows:

echo "starting...";
$appsyncServer = "myserver";
$LoginUri = "https://".$appsyncServer.":8444/cas-server/login?TARGET=https://".$appsyncServer.":8445/appsync/";
$ch = curl_init($LoginUri);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, '-');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$curl_response = curl_exec($ch);

echo "
"
;
if ($curl_response === false) {
   $info = curl_getinfo($ch);
   $error = curl_error($ch);
   curl_close($ch);
   echo "
The error:
"
;
   print $error;
   echo "
More details
"
;
   die('error occured during curl exec. Additional info: ' . var_export($info));
}
$login_arr = array("username" => "myuser" , "password" => "mypassword");
$ch = curl_init($LoginUri);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $login_arr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$curl_response = curl_exec($ch);

curl_close($ch);
print_r($curl_response);
echo "
done!"
;
?>

Thanks in advance!

No Responses!
No Events found!

Top