Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

How to Generate Token for Report with Shared Dataset?

The code snippet below works fine for a Generic Report which means with Internal Dataset, however If I try to GenerateToken for a Report with an External Dataset meaning a Dataset that lives in another Workspace it throws a 403 Forbidden.

 

Note: I'm using SPN to authenticate my request and SPN is an Admin of Both Workspace (Workspace where the External Dataset Lives and Workspace where the Report lives)

 

using (var pbiClient = await this.GetClientAsync().ConfigureAwait(false))
{
  

if (pbiClient != null)
{
var dataset = await pbiClient.Datasets.GetDatasetByIdInGroupAsync(groupId, datasetId).ConfigureAwait(false);

GenerateTokenRequest genereateTokenRequestParameters;

var identity = new EffectiveIdentity(user.Username.Trim(), new List<string> { dataset.Id })
{
Roles = new List<string> { securityRole }
};

 

genereateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view", identity: identity);

 

// THIS LINE OF CODE RETURNS 403 FOR REPORT WITH EXTERNAL DATASET,

// WHILE WORKS IF REPORT AND DATASET IS IN THE SAME WORKSPACE
var tokenResponse = await pbiClient.Reports.GenerateTokenInGroupAsync(reportGroupId, report.Id, genereateTokenRequestParameters).ConfigureAwait(false);

 

embedReport.EmbedToken = tokenResponse ?? throw new NullReferenceException($"Power BI token not generated. Report ID: {report.Id}");

 

embedReport.EmbedUrl = report.EmbedUrl;
embedReport.ReportId = report.Id;

return embedReport;
}

 

}

 

 

No Replies