The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
I created an asp.net api that uses Service Principal to connect to AAD and generate embed tokens, and sends that token to my frontend. It is working well when I use old reports that some of my colleages published last summer, however, we are trying to use Azure Analysis Services and created some new reports to test it.
The api isn't able to generate the embed tokens for these new reports, throwing instead a BadRequest 500. Also while I was figuring out RLS I published another report from a sample given by Microsoft and the same BadRequest happens for the sample report. Are we forgetting some kind of configuration needed to generate tokens? I understand the erros with the reports using AAS but the one I published does not use it afaik.
Here is my code:
private static readonly string Tenant = "tenant";
private static readonly string AppId = "id";
private static readonly string AppSecret = "secret";
private static readonly string Resource = "https://analysis.windows.net/powerbi/api";
private string getToken()
{
var authContext = new AuthenticationContext(Tenant);
var clientCredential = new ClientCredential(AppId, AppSecret);
return authContext.AcquireTokenAsync(Resource, clientCredential).Result.AccessToken;
}
private PowerBIClient getPBIClient()
{
var token = new TokenCredentials(getToken(), "Bearer");
return new PowerBIClient(new Uri("https://api.powerbi.com/"), token);
}
public async Task<ODataResponseListReport> getReports(string ws)
{
PowerBIClient pbiClient = getPBIClient();
var reports = await pbiClient.Reports.GetReportsInGroupAsync(ws);
return reports;
}
public async Task<ReportEmbeddingData> getReportEmbeddingData(string ws, string rep)
{
PowerBIClient pbiClient = getPBIClient();
var report = await pbiClient.Reports.GetReportInGroupAsync(ws, rep);
var embedUrl = report.EmbedUrl;
var reportName = report.Name;
GenerateTokenRequest genTokenReqParam = new GenerateTokenRequest(accessLevel: "view");
string embedToken = (await pbiClient.Reports.GenerateTokenInGroupAsync(ws, rep, genTokenReqParam)).Token;
return new ReportEmbeddingData
{
type = "report",
reportId = rep,
reportName = reportName,
embedUrl = embedUrl,
accessToken = embedToken
};
}
}
Hi @Anonymous
I have a similar issue in my production environment. Everything seems to be working correctly on my localhost, but when I moved to prod I don't receive the embed token.
Did you solve this? How did you do it?
Thank you in advance.