Trusted Authentication using PHP with cURL (DokuWiki)

Version 1

    I had issues getting pecl_http installed for php as per the provided examples so I went down the route of using cURL instead. There are a couple of differences so I thought it would be useful to share how to do this.


    Specifically this shows how to achieve trusted authentication on dokuwiki to allow embedding of visualizations but the PHP code should be transferable.


    To enable this to work on dokuwiki you must turn on embedded php within the admin section's config settings.


    Firstly, for dokuwiki, you need to add ~~NOCACHE~~ anywhere in the page. This is required when viewing dynamic content on dokuwiki.


    The <php> tag is the start of the embedded php. If you're not using dokuwiki, whatever is between this and the closing page is all you care about.


    One of the main differences here is that in the php example provided by Tableau, the username is passed as an array, whereas when using cURL it should be passed as a key=value string.



    ====== Testing embedding of tableau ======


    $userid = $_SERVER['REMOTE_USER'];

    if ($userid) {

        echo 'debug: Authenticated on tableau as ', $userid, '<br />';

        $loginparams = 'username='. $userid;

        $urlparams = ':embed=yes&:toolbar=no';

        $url = '';

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL,$url);

        curl_setopt($ch, CURLOPT_POST, 1);

        curl_setopt($ch, CURLOPT_POSTFIELDS,$loginparams);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));

        $ticket = curl_exec ($ch);

        curl_close ($ch);


        echo '<iframe src=', $url, $ticket, '/views/WORKBOOK_NAME/VIEW_NAME?', $urlparams, '"

                width="700" height="400">


    } else {

        echo 'Log on to see Tableau content';




    Why might this be useful on dokuwiki? In our case, we are creating a page for every ETL job we have, the name of the page will be the etl job. We can pass the page name in as a filter and return information on the ETL job, such as frequency of execution, duration, records processed etc. If you have anything where you are have a mixture of reportable metadata and user defined content, this can all be displayed in the one location