Forum Discussion
How to embed some Power BI Tiles in a Rails App?
Congratulations !
Agree on the bugs, even the CLI not running on mac took me a few hours to work out :smileysad:
Can I ask so you are using just the main access key not generating a short time key ?
If so how to secure it or not a factor in your use case.
Thanks.
Hi there.
I'm not sure to understand your question, most of the things I've done so far are beyond my own comprehension :-)
I'm using the "KEY 1" associated with the WorkSpace collection created on Azure portal.
Maybe this will help you.
Here's the CLI commands:
$ powerbi get-workspaces -c MyWorkspaceCollection -k TheVeryLongKey1IHaveCopiedOnTheAzurePortal123456789= $ powerbi create-workspace -c MyWorkspaceCollection -k TheVeryLongKey1IHaveCopiedOnTheAzurePortal123456789= $ powerbi import -c MyWorkspaceCollection -w TheWorkspaceIDIHaveJustCreated54321 -k TheVeryLongKey1IHaveCopiedOnTheAzurePortal123456789= -f ~/Downloads/Retail\ Analysis\ Sample.pbix -n "Retail Analysis Sample" $ powerbi get-reports -c MyWorkspaceCollection -w TheWorkspaceIDIHaveJustCreated54321 -k TheVeryLongKey1IHaveCopiedOnTheAzurePortal123456789=
In Rails, my controller is:
require 'jwt'
class JwtController < ApplicationController
ACCESSKEY = "TheVeryLongKey1IHaveCopiedOnTheAzurePortal123456789"
TOKEN1 = {
"typ" => "JWT",
"alg" => "HS256",
"wid" => "TheWorkspaceIDIHaveJustCreated54321",
"rid" => "TheReportIDIHaveRetreived134679",
"wcn" => "MyWorkspaceCollection",
"iss" => "PowerBISDK",
"ver" => "0.2.0",
"aud" => "https://analysis.windows.net/powerbi/api",
"nbf" => Time.now.to_i,
"exp" => Time.now.to_i + 4 * 3600
}
def connect
@token = JWT.encode TOKEN1, ACCESSKEY, 'HS256'
end
endFinally, the view:
<button id="btnView">View Report !</button>
<div id="divView">
<iframe id="ifrTile" width="100%" height="400"></iframe>
</div>
<script>
(function () {
document.getElementById('btnView').onclick = function() {
var iframe = document.getElementById('ifrTile');
iframe.src='https://embedded.powerbi.com/appTokenReportEmbed?reportId=TheReportIDIHaveRetreived134679';
iframe.onload = function() {
var msgJson = {
action: "loadReport",
accessToken: "<%= @token %>",
height: 800,
width: 800
};
var msgTxt = JSON.stringify(msgJson);
iframe.contentWindow.postMessage(msgTxt, "*");
};
};
}());
</script>
Hope, it will help you or anyone else.
Cheers
- metricsman9 years agoHelper I
I think your understand is better than mine...
Haven't used Rails but I think it's if the accesskey in the controller can be seen by an end-user they then can access the workspace.
That was form: https://azure.microsoft.com/en-us/documentation/articles/power-bi-embedded-iframe/
"But, when we embed the report in our web page, this kind of security information would be handled using JavaScript (frontend). Then the authorization header value must be secured. If our access key is discovered by a malicious user or malicious code, they can call any operations using this key."
So I've gone some complicated path of having a used call an "api" that uses the accesskey to return the shorter term token - same as what your controller does I think.