Quantcast
Channel: Developer topics
Viewing all articles
Browse latest Browse all 17873

Power BI embedded - switch to premium in php application

$
0
0

Hi there - I'm currently making the switch from Power BI workspace collections to the new model. Previously I used embedded in a PHP application (I'm not a professional PHP developer, though I work with Power BI + BI architecture every day).

 

Unfortunately, all of the documentation is in c# for ASP.net development. 

 

Obviously, I dont wan't to reinvent the wheel, and would need for this to work in PHP which is where our development Minimum Viable Product currently is.

 

This is the code that I used before, which is from an old embedded Microsoft tutorial (which was great!) 

 

Will it be possible to amend the code below for the new model, or do I need to start from scratch?

 

<!--?php 
// 1. power bi access key
$accesskey = "HIDDEN";
// 2. construct input value
$token1 = "{" . "\"typ\":\"JWT\"," . "\"alg\":\"HS256\"" . "}";
$token2 = "{" . "\"wid\":\"HIDDEN\"," .
// workspace id
"\"rid\":\"HIDDEN\"," .
// report id
"\"wcn\":\"HIDDEN\"," .
// workspace collection name "\"iss\":\"HIDDEN\"," . "\"ver\":\"0.2.0\"," . "\"aud\":\"https://analysis.windows.net/powerbi/api\"," . "\"nbf\":" .
date("U") . "," . "\"exp\":" . date("U" , strtotime("+1 hour")) . "}";
$inputval = rfc4648_base64_encode($token1) . "." . rfc4648_base64_encode($token2);
// 3. get encoded signature value
$hash = hash_hmac("sha256", $inputval, $accesskey, true);
$sig = rfc4648_base64_encode($hash);
// 4. get apptoken
$apptoken = $inputval . "." . $sig;
// helper functions
function rfc4648_base64_encode($arg) { $res = $arg;
$res = base64_encode($res);
$res = str_replace("/", "_", $res);
$res = str_replace("+", "-", $res);
$res = rtrim($res, "="); return $res; } ?--><button id="btnView" class="et_pb_contact_submit et_pb_button">Open Report</button><div id="divView"><iframe id="ifrTile" width="100%" height="700"></iframe></div><script> (function () { document.getElementById('btnView').onclick = function() { var iframe = document.getElementById('ifrTile'); iframe.src="https://app.powerbi.com/appTokenReportEmbed?reportId=HIDDEN"; iframe.onload = function() { var msgJson = { action: "loadReport", accessToken: "<?=$apptoken?>", height: 500, width: 722 }; var msgTxt = JSON.stringify(msgJson); iframe.contentWindow.postMessage(msgTxt, "*"); }; }; }());</script>

Viewing all articles
Browse latest Browse all 17873

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>