title: responsive iframe + Tableau trusted authentication
body: <p>I'm embedding Tableau views in a PHP web application.  We had been using an enabled guest account with Tableau Server which basically allowed for anonymous authentication.  Under this scheme, responsive embeds were straightforward, and working great, using a javascript solution such as fitvids.js/fluidvids.js.</p>
  
  <p>Recently, we made the change to trusted authentication which passes a specific user to Tableau Server from the web app, generates a unique, one-time trusted ticket, and renders the view.  With a standard, fixed embed, everything works as expected.  However, when implementing fitvids.js or fluidvids.js, we get the dreaded Tableau error: <code>Could not locate unexpired trusted ticket</code>.</p>
  
  <p>My best guesses are that the breakdown is either: </p>
  
  <ol>
  <li>PHP for ticket generation and url creation </li>
  <li>processing order of javascript (most likely)</li>
  <li>Tableau Server limitation</li>
  </ol>
  
  <p>A css only solution will not work as the content inside the iframe is dynamic.  </p>
  
  <p>For reference, here is the php in question:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  /**
   * Implementation of Tableau trusted auth for php
   *
   * http://onlinehelp.tableausoftware.com/v8.1/server/en-us/trusted_auth_webURL.htm
   */
  function get_trusted_url($user, $server, $view_url, $site) {
    $params = ':embed=yes&amp;:toolbar=yes:tabs=no';
    $ticket = get_trusted_ticket($server, $user, $_SERVER['REMOTE_ADDR'], $site);
  
    return "http://$server/trusted/$ticket/$view_url?$params";
  }
  
  // Note that this function requires the pecl_http extension.
  // See: http://pecl.php.net/package/pecl_http
  
  // the client_ip parameter isn't necessary to send in the POST unless you have
  // wgserver.extended_trusted_ip_checking enabled (it's disabled by default)
  function get_trusted_ticket($wgserver, $user, $remote_addr, $site) {
    $params = array(
      'username' =&gt; $user,
      'client_ip' =&gt; $remote_addr,
      'target_site' =&gt; $site
    );
  
    return http_parse_message(http_post_fields("http://$wgserver/trusted", $params))-&gt;body;
  }
  ?&gt;
  </code></pre>
  
  <p>And an example embed:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;iframe src="&lt;?php echo get_trusted_url($user,$server,$view_url,$site);?&gt;"&gt;&lt;/iframe&gt;
  </code></pre>