Been searching for a while without sucess for a solution. Also, I'm really not experimented in php and REST API, so apologies for any newbie mistakes.
I need to 1) send a POST request to a server and get cookies associated to my login 2) reuse these cookies with url based on that same server, which runs a report.
To perform this I use php and cURL. The below script works fine:
<?php
$homeurl = "http://localhost:8080/pentaho/j_spring_security_check?j_username=admin&j_password=admin&locale=en_US";
$reporturl = 'http://localhost:8080/pentaho/api/repos/:public:IframeDossier:IframeTest.prpt/viewer?label=fin';
$cookie_jar = tempnam('/Users/pierre/Vrac','cookie');
if (!file_exists(realpath($cookie_jar))) touch($cookie_jar);
//login and get cookies
$ch = curl_init($homeurl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$return = curl_exec($ch);
// run report url using cookies
echo "execution report";
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($ch, CURLOPT_URL, $reporturl);
$page = curl_exec($ch);
echo $page;
curl_close($ch);
?>
I get the expected return:
"HTTP/1.1 100 HTTP/1.1 415 Set-Cookie: session-expiry=1542901561740; Path=/ Set-Cookie: server-time=1542894361740; Path=/ Content-Length: 0 Date: Thu, 22 Nov 2018 13:46:01 GMT Connection: close"
now instead I would like to embed $reporturl into an Iframe. I've built the following Iframe:
<iframe id="inlineFrameExample"
title="Inline Frame Example"
width="1000"
height="2000" src="http://localhost:8080/pentaho/api/repos/:public:IframeDossier:IframeTest.prpt/viewer?label=fin">
</iframe>
My Iframe runs correctly when I call its url.
I am now calling the Iframe url in my code. so
curl_setopt($ch, CURLOPT_URL, $reporturl);
becomes
curl_setopt($ch, CURLOPT_URL, http://localhost:8080/IframeTest.html);
the problem is that now, my browser asks for authentication, while my Iframe should already have this authentication using cookies retrieved in the first step of the code. I must be doing something wrong, but cant' figure out what... any help much appreciated.
thanks