Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Sanjana
Frequent Visitor

unable to generate token using the datasetid for reports using effective identity

using (var client = new PowerBIClient(new Uri(API_URL), new TokenCredentials(accessToken, "Bearer")))
{
Report powerBiReport = await client.Reports.GetReportInGroupAsync(groupId, reportId.ToString());
#region default
var generateTokenRequestParameters = new GenerateTokenRequest("view", null, identities: new List<EffectiveIdentity> { new EffectiveIdentity(username: username, roles: roles, datasets: new List<string> { powerBiReport.DatasetId }) });
var token = await client.Reports.GenerateTokenInGroupAsync(groupId, reportId, generateTokenRequestParameters);

}

 

it works fine without effectiveidentity ut it fails with effective identity. Please help in identifying the parameters

1 ACCEPTED SOLUTION
Jayendran
Solution Sage
Solution Sage

Hi @Sanjana ,

 

What do you mean by fails , do you get any error ? pls share that.

 

  • Make sure that username ,roles are not having null values
  • Make sure your reports developed using the RLS
                    if (datasets.IsEffectiveIdentityRolesRequired == true)
                    {
                        if (!string.IsNullOrWhiteSpace(username))
                        {
                            var rls = new EffectiveIdentity { Username = username, Roles = new List<string> { roles }, Datasets = new List<string> { report.DatasetId } };

                            if (!string.IsNullOrWhiteSpace(roles))
                            {
                                var rolesList = new List<string>();
                                rolesList.AddRange(roles.Split(','));
                                rls.Roles = rolesList;
                            }
                            // Generate Embed Token with effective identities.
                            generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view", identities: new List<EffectiveIdentity> { rls });
                        }
                       
                    }

Try the above code which having more condition for you to check

View solution in original post

1 REPLY 1
Jayendran
Solution Sage
Solution Sage

Hi @Sanjana ,

 

What do you mean by fails , do you get any error ? pls share that.

 

  • Make sure that username ,roles are not having null values
  • Make sure your reports developed using the RLS
                    if (datasets.IsEffectiveIdentityRolesRequired == true)
                    {
                        if (!string.IsNullOrWhiteSpace(username))
                        {
                            var rls = new EffectiveIdentity { Username = username, Roles = new List<string> { roles }, Datasets = new List<string> { report.DatasetId } };

                            if (!string.IsNullOrWhiteSpace(roles))
                            {
                                var rolesList = new List<string>();
                                rolesList.AddRange(roles.Split(','));
                                rls.Roles = rolesList;
                            }
                            // Generate Embed Token with effective identities.
                            generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view", identities: new List<EffectiveIdentity> { rls });
                        }
                       
                    }

Try the above code which having more condition for you to check

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.