Forum Discussion
App only authentication - oAuth2 token request
- 7 years ago
Hi ricus_zero you can use the below query in postman, basically you should use the grant type as client_credentials
resource:https://analysis.windows.net/powerbi/api
client_id:xxxxx
client_secret:xxxx
grant_type:client_credentials
Hi ricus_zero
Am I correct in saying that it's possible for a normal license to create new workspaces via the service principle? (API call)
Yes you are correct
You shouldn't use get dashboard API using SPN token Instead use get dashboard in group
Now a seemingly simple question of, how do I actually use this embed token in our web app to display the embedded dashboard?
You can use SDK's See App owns data in dotnet
Basically you need to pass the embed token to PowerBI Javascript
<script>
// Read embed application token from Model
var accessToken = "@Model.EmbedToken.Token";
// Read embed URL from Model
var embedUrl = "@Html.Raw(Model.EmbedUrl)";
// Read dashboard Id from Model
var embedDashboardId = "@Model.Id";
// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;
// Embed configuration used to describe the what and how to embed.
// This object is used when calling powerbi.embed.
// This also includes settings and options such as filters.
// You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
var config = {
type: 'dashboard',
tokenType: models.TokenType.Embed,
accessToken: accessToken,
embedUrl: embedUrl,
id: embedDashboardId
};
// Get a reference to the embedded dashboard HTML element
var dashboardContainer = $('#dashboardContainer')[0];
// Embed the dashboard and display it within the div container.
var dashboard = powerbi.embed(dashboardContainer, config);
</script>BTW you can give Like/give kudo's to my replies if you find it useful, by this way it will help others.
Hi Jayendran
I've given you a few thumbs-ups for your help, and will mark a solution soon.
I'm running Linux so don't have a c# environment, but I pulled down the javascript package from their Github.
I was a little confused with where the value of embedUrl comes from, since it's not in the response, but fiddling a little I figured out it's just https://app.powerbi.com/dashboardEmbed?dashboardId=XXX
I've now been able to embed both a dashboard and a report in my sample web app, making use of the embed token functionality, and once again thanks so much for your help today, I've been struggling with this for over a week.
I did notice the lifetime of that token from embed token isn't very long, so it's something I would need to keep in mind when developing the full application.
Hope you have a great day.
Thanks again!
- Jayendran7 years agoSolution Sage
Hi ricus_zero Glad that you solved your problem.
for your question you can find the answer in below.
https://community.powerbi.com/t5/Developer/PowerBI-Embedded-Embed-Token-Expiration/td-p/54535
Also in the code you can config it