Forum Discussion
Get an Azure AD access token for embedding reports using JavaScript
Thanks you Jayendran!
I have tried this code, it does get me a token but it seems like the token is not valid.
1. this is where i fetch the token from the script you mentioned and assign it to a variable:
ybdtoken = token;
function userSignedIn(err, token) {
console.log('userSignedIn called');
console.log('L35-token is: ', token);
ybdtoken = token;
if (!err) {
showWelcomeMessage();
}
else {
console.error("error: " + err);
}
}2. I use it later on in the powerbi.embed() function and pass all relevent parameters, including the token i have extracted after the user prefourmed a login to his power bi account:
function ybdEmbed(YbdEmbeddedReportId, YbdEmbeddedReportUrl){
// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;
console.log("models: ",models);
//console.log("out function ybdAccessToken: ", ybdAcessToken);
//console.log("token: ",token);
var embedConfiguration = {
type: 'report',
id: YbdEmbeddedReportId,
embedUrl: YbdEmbeddedReportUrl,
tokenType: models.TokenType.Aad,
accessToken: ybdtoken
};
console.log("embedConfiguration: ", embedConfiguration);
var $reportContainer = jQuery('#reportContainer');
console.log("$reportContainer", $reportContainer);
var report = powerbi.embed($reportContainer.get(0), embedConfiguration);
}But for some reason it looks like the token i get is invalid:
when i try to embed a report using powerbi.embed() function the report i frame loads but i get an error message asking me to ask for access to this report (in power bi desktop i have already added the user to the report work space)
When i generate a token via GET https://api.powerbi.com/v1.0/myorg/reports:
the token works fine and i can see my embedded report
any idea what can cause this?
thanks!!!
in general, if i use msal.js or adal.js i get a token but looks like the token is invalid as i can't access the report
- mittalpatel1306 years agoHelper III
Hi..
Could you find any solution to your code? I also get the same issue.
When you created Azure AD App, what should be the Redirect URI? is it embed Page URL?
Thank you in advance!
- Anonymous6 years agoNot applicable
Have you find solution?
I'm facing same issue in my application.