0 votes
1 view
in BI by (17.6k points)

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 a 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

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')

image

1 Answer

0 votes
by (47.2k points)
  • You have to 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.

  • A value need to be provided for target_site (even a zero length string) which is necessary as it tells us which Tableau site you're requesting a ticket for. Blank/zero length string = "Default site", essentially.

  • 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;

  • file_get_contents() might be seen as a 'better' approach than http_parse_message() in the PHP community, 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 we know Tableau has multi-tenancy.

  • Here is the  sample code which can be found in C:\Program Files (x86)\Tableau\Tableau Server\7.0\extras\embedding\php

Related questions

0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...