diff --git a/php_wordpress/README.md b/php_wordpress/README.md new file mode 100644 index 0000000..a1ce5a4 --- /dev/null +++ b/php_wordpress/README.md @@ -0,0 +1,11 @@ +# Tableau Connected Apps Direct Trust JWT Generation (Wordpress + PHP) + +## Prerequisites +- A Wordpress Site or other PHP site + +## Getting Started + +1. Update the config variable in 'tableau-embed.php' with your Tableau +1. Add the folder tableau-embed to your Wordpress Plugins Folder +1. Enable the Plugin in [Wordpress](https://wordpress.com/support/plugins/install-a-plugin/) +1. Add a tableau shortcode block to your Wordpress site diff --git a/php_wordpress/tableau-embed/tableau-embed.php b/php_wordpress/tableau-embed/tableau-embed.php new file mode 100644 index 0000000..3d94944 --- /dev/null +++ b/php_wordpress/tableau-embed/tableau-embed.php @@ -0,0 +1,103 @@ + 'JWT', + 'alg' => 'HS256', + 'kid' => $kid, + 'iss' => $iss + + ]; + // Encode header + $stringifiedHeader = json_encode($header); + $encodedHeader = base64url_encode($stringifiedHeader); + + // Set JWT Payload attributes, + // May want to set more varialbes i.e. Groups and ODA + // Scopes may need additional designations + // see documentation for more information, + $payload = [ + 'iss' => $iss, + 'exp' => time() + (60*$expiration), + 'jti' => uniqid(), + 'aud' => 'tableau', + 'sub' => $username, + 'scp' => ["tableau:views:embed"] + ]; + + // Encode payload + $stringifiedData = json_encode($payload); + $encodedData = base64url_encode($stringifiedData); + + // Build token + $token = $encodedHeader . '.' . $encodedData; + + // Sign the JWT, this is meant to only be done on the backend for security purposes + $signature = hash_hmac('sha256', $token, $key, true); + $encodedSignature = base64url_encode($signature); + $jwt = $token . '.' . $encodedSignature; + + + //Starting object capture + //all html content to embed goes into this block + ob_start(); + ?> + + + + + + + +