9 Replies Latest reply on Sep 6, 2017 5:43 AM by Ghouse Shaik

    Auto Login with PHP

    Naser Sobhan

      Hi,

       

      In our organization, we have multiple dashboards but we need single login to all, we can't make them be public, most of our dashboard developed with PHP and Java, now we have our own login system, now we want autologin with PHP to tableau Dashboard (static single user like "user" with password of "password" only view reports) , like when we user login to our Main web portal, it should autologin to tableau dashboard too.

       

      I have tried ticket, it's not working (I don't know why) but I can't get the ticket.

       

      what should I, is there anyway that I can get the login token in tableau login page and auto login using php, or any other way

       

       

      thank you.

        • 1. Re: Auto Login with PHP
          Michael Bodell

          Can you provide more details of your Tableau Server configuration?  Are you using local users? Active Directory? Trusted Authentication?

           

          The first thing that comes to my mind would be to create a single user for this limited "view only" purpose in Tableau Server (assuming you're not using Active Directory).  Then configure Tableau Server for trusted authentication (Tableau Server will need to trust the server where the PHP code / website is running).  You can then embed a view in your PHP page.  This embedded view can be configured to request a ticket for the user you created (hard code the user in the PHP page) and then use that ticket in the URL to the Tableau view that will be rendered in the page.

           

          Trusted Authentication - this resource has details of how trusted authentication works as well as examples that can be adapted for  your scenario.

          1 of 1 people found this helpful
          • 2. Re: Auto Login with PHP
            Vien Hua

            I believe hard coding the user in for something like this would be violating the EULA

            • 3. Re: Auto Login with PHP
              Michael Bodell

              You may be right about the EULA. Based on the original question I was not sure if the page was for public consumption or internal only.

               

              For example, if you are already using trusted auth to allow internal users to access the Tableau viz, then you have probably turned the guest account off.  In this scenario, if you still have a Viz that is intended to public consumption on the website, you have no way to enable it unless you do what I described.

               

              That said, if the users in Tableau (usernames) match the users (usernames) that are used to log in to the PHP site, then you can use trusted auth in the way it was intended and not in violation of any EULA.  You simply need to be able to obtain the username of the user in the PHP page and use that to request the auth ticket from Tableau Server.  Of course you also need to enable trusted authentication and add the PHP server (IP or Name/FQDN) to the list of trusted hosts on the Tableau Server.

               

              This resource should provide some guidance. Trusted Authentication

               

              There are also some example resources in the Tableau Embedding folder on your Tableau Server (included with your install).  One of these examples is for PHP.

              • 4. Re: Auto Login with PHP
                Vien Hua

                Absolutely Michael! As long as you can obtain the username from the PHP script, that username can be sent to request a ticket and then use in trusted auth. Here's a sample script:

                 

                $username = $_POST['username']; # Retrieve username from user's input

                $server = $_POST['server'] . "/trusted"; # Retrieve server URL from user's input and add /trusted

                $site = $_POST['site']; # Retrieve site ID from user's input

                $view = $_POST['view']; # Retrieve view URL from user's input

                 

                $ch = curl_init($server); # Initialize cURL session

                 

                $data = array('username' => $username, 'target_site' => $site); # Data to send, add site ID or IP address for validation if desired. For example:

                # array('username' => $username, 'target_site' => $site_id, 'client_ip' => $client_ip_address)

                # See http:#onlinehelp.tableausoftware.com/current/server/en-us/help.htm#trusted_auth_webrequ.htm

                 

                curl_setopt($ch, CURLOPT_POST, true); # Tells cURL to use POST method

                curl_setopt($ch, CURLOPT_POSTFIELDS, $data); # Tells cURL what data to post

                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # Return ticket in a variable instead of displaying it on the screen

                 

                $ticket = curl_exec($ch); # Execute cURL function which will post to Tableau Server and retrieve ticket into this variable

                 

                curl_close($ch); # Close the cURL session

                 

                <iframe src="$server/$ticket/$view" width="600" height="600"></iframe> # For default site

                <iframe src="$server/$ticket/t/$site/$view" width="600" height="600"></iframe> # For non-default site

                • 5. Re: Auto Login with PHP
                  Ghouse Shaik

                  Hi Naser,

                  Go to the bin folder of the Tableau Server and run the following commands to get Trusted Authentication for the IP Address

                            1.tabadmin stop

                            2.tabadmin set wgserver.trusted_hosts IP_Address_Assigned_To_Trusted

                            3.tabadmin config

                            4.tabadmin start

                   

                  Create a New File in htdocs of the XAMPP folder with .php extension (Example : webportal.php) and Use the following Syntax to embed a Tableau Workbook in Web Portal.

                   

                  <?php

                  $url = 'URL_of_Tableau_Server_With_Port_Number/trusted';

                  $server = URL_of_Tableau_Server_With_Port_Number ';

                  $data = array('username' => ' Administrator_User_Of_The_Tableau_Server ');

                  $params = ':embed=yes&:toolbar=yes';

                  $views = 'Views_URL_Of_The_Embedded_Workbook;

                   

                  // use key 'http' even if you send the request to https://...

                  $options = array(

                      'http' => array(

                  'header'  => "Content-type: application/x-www-form-urlencoded\r\n",

                  'method'  => 'POST',

                  'content' => http_build_query($data)

                      )

                  );

                  $context = stream_context_create($options);

                  $result = file_get_contents($url, false, $context);

                  if ($result === FALSE) { /* Handle error */ }

                   

                  $workbook = $url.'/'.$result.'/'.$views.'?'.$params;

                   

                  ?>

                  <script type="text/javascript" src="https://public.tableau.com/javascripts/api/tableau-2.js"></script>

                  <script type="text/javascript">

                                  var viz;

                   

                                  window.onload = function(){

                                  var vizDiv = document.getElementById('myViz');

                                  var vizURL = "<?php echo $workbook;?>";

                                  var options = {

                                                  width: 'Width_Of_The_Embedded_Workbook_in_Web_Portal',

                                                  height: 'Height_Of_The_Embedded_Workbook_in_Web_Portal'

                                  };

                                  viz = new tableau.Viz(vizDiv, vizURL, options);

                  };

                   

                  //Content below is Resolving warning for missing 'tableau' object

                  var tableau;

                  </script>

                   

                  <div id="ID_Of_The_Embedded_Workbook_in_Web_Portal_Where_You_Want_To_Publish "></div>

                   

                  Please revert back if you have any further queries.

                   

                  Regards,

                  Ghouse Shaik.

                  • 6. Re: Auto Login with PHP
                    IT SIB

                    Hi, I have the same question but it goes with Tableau Online. And with your code it doesn't work. Any suggestion?

                    • 7. Re: Auto Login with PHP
                      Vien Hua

                      Trusted authentication cannot be used with Tableau Online.

                      • 8. Re: Auto Login with PHP
                        IT SIB

                        Is there any alternative for Tableau Online of this purpose?

                        • 9. Re: Auto Login with PHP
                          Ghouse Shaik

                          Hi IT SIB,

                           

                          I think Alternative way is to use SAML Authentication.

                           

                          Thanks & Regards,

                          Ghouse Shaik.