I see there aren't many Tableau experts floating around StackOverflow, but perhaps someone out there has had this problem before, and knows the solution. I'm a total noob at Tableau, so please forgive me if this question is inane. Thanks in advance!
The System
The way we have Tableau set up is on an server separate from the webserver. The application is written in PHP, using CakePHP 2.2.0 stable.
10.0.0.10 - webserver
10.0.0.11 - tableau
In order to have a client view a report generated by Tableau, we are using the trusted authentication ticketing system, where the client is issued a URL with a specific ticket. The client then uses this ticket to ask the tableau server directly for the report.
An example:
The Issue
The problem is this: When the code asks for the tableau ticket number (steps 2 & 3 above), the Tableau server responds with an authentication page, not a ticket ID. If I comment out the "target_site" parameter in the $postdata array, tableau does not respond with a login page and instead simply says "-1".
The PHP code to generate the trusted URL:
<?php
public function get_trusted_url($view = 'book2sheet1') {
$email = $this->Auth->user();
$email = $email['Email']; //This email is registered as a Tableau user!
$postdata = http_build_query(
array(
'username' => $email,
'target_site' => 'oursite', //If I comment this line out, Tableau no longer returns an auth page and instead simply returns "-1"
'client_ip' => $_SERVER['REMOTE_ADDR']
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$ticket = file_get_contents('http://10.0.0.11/trusted/', false, $context);
if($ticket > 0) {
return 'http://tableau.example.com/t/rg/trusted/' . $ticket . '/' .$view . '?:embed=yes&:comments=no&:toolbar=yes';
} else {
echo 'failure'; //debug
print_r($ticket); //debug - this prints out the auth page
return false;
}
}
Any help would be greatly appreciated! As I mentioned, I'm a total noob at Tableau :)
Image of the returned login html, dumped to the page using print_r('ticket')
Thank you!
... Tableau Server returns -1 for the ticket value if it cannot issue the ticket as part of the trusted authentication process. Before troubleshooting this scenario, be sure to set the log level for trusted authentication to debug as specified in Troubleshoot Trusted Authentication.
The first step to any of this is enabling Unrestricted Trusted Tickets. An unrestricted trusted ticket is a full Tableau session that can see the UI; regular trusted tickets only allow access to workbooks and views.
The ticket format changed in Tableau Server 10.2. The ticket format is now a string composed of two parts. Each part is a 128 bit string that is encoded before it is returned to the client. The first part is a universally unique ID (UUID v4) that is Base64-encoded.
Server POSTS to 10.0.0.11, and asks for a ticket for the client to view report 3 Tableau Server responds to the post with a number, e.g. 987654321. Server responds to the client's GET with the page, including the ticket.
You must use the site ID and not the 'name'. Also be careful that the site name and ID are not the same string, as that resulted in the html page being returned; ensure that your site name and ID are different!
The first thing I would do is make sure that Trusted Ticketing is working in a vacuum. This link http://ttrequest.notlong.com will land you in a folder which contains a simple HTML/JavaScript page you can use to make sure everything is configured correctly. Then, look more closely at your code.
Providing a value for target_site (even a zero length string) is necessary as it tells us which Tableau site you're requesting a ticket for. Blank/zero length string = "Default site", essentially.
I know very little PHP, but Tableau provides some sample code which I've used in the past. It doesn't use file_get_contents()
to do the POST, but instead leans on http_parse_message()
...and it works for me:
Function get_trusted_ticket_direct($server, $user, $targetsite) {
$remote_addr = $_SERVER['REMOTE+ADDR'];
$params = array(
'username' => $user,
'client_ip' => $remote_addr,
'target_site' => $targetsite
);
$ticket= http_parse_message(http_post_fields("http://$server/trusted", $params))->body;
if ($ticket > 0) {
return $ticket;
}
else
return 0;
}
I honestly don't know if file_get_contents() is seen as a 'better' approach than http_parse_message() in the PHP community (maybe someone can comment on this), but the sample code is solid except for the fact that it still doesn't include a reference to the target_site parameter (as it was written way before Tableau had multi-tenancy).
The sample code can be found in C:\Program Files (x86)\Tableau\Tableau Server\7.0\extras\embedding\php
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With