this curl in the command line in my Terminal
curl -c session_cookies.txt "https://login.uat.site.be/openid/oauth/authorize?client_id=site&st
Most likely the problem is that your first request fails cause you don't setup SSL verifying properly. You have to set the same CURL options for both requests. The difference is only URL and POST data.
So the code should look like this:
$cookie_file = public_path(). '/session_cookies.txt';
if (!file_exists($cookie_file)) return;
$pem_file_path = '/Applications/MAMP/conf/apache/openid.benu.com.cert.pem';
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_CAINFO=> $pem_file_path,
CURLOPT_POST => true,
CURLOPT_COOKIEJAR => $cookie_file,
CURLOPT_COOKIEFILE => $cookie_file,
);
$ch = curl_init('https://login.uat.site.be/openid/oauth/authorize');
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
'client_id' => 'benu',
'state' => $state,
'nonce' => $nonce,
'claims' => '%7B%22id_token%22%3A%7B%22http%3A%2F%2Fsite.be%2Fclaims%2Froles%22%3Anull%7D%7D',
'response_type' => 'code'
)));
$result = curl_exec($ch);
$err = curl_errno($ch);
curl_close($ch);
if ($err) {
echo 'Error:' . curl_error($ch); return;
}
$ch = curl_init('https://login.uat.site.be/openid/login.do');
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
'j_username' => 'manager-sitelogin@gmail.com',
'j_password' => 'site1',
)));
$result = curl_exec($ch);
$err = curl_errno($ch);
curl_close($ch);
if ($err) {
echo 'Error:' . curl_error($ch);
}