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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
datavigilante
Helper I
Helper I

Need help implementing row-level security (RLS) with embedded analytics

Hello all,

 

It looks like Microsoft just added some functionality to the GenerateToken API so that you can pass additional context for RLS as a part of your embed token:

 

https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-embedded-rls/

 

Does anyone happen to have a simple working example of this that they can share?  I just want to pass one user, role and dataset, but I don't know how to determine the dataset ID.

 

Sorry, if this is a dumb question, but how do I determine what the id is for the dataset of my report?

 

thanks!

David

1 ACCEPTED SOLUTION
craigduffy
Regular Visitor

I had the same question. Just figured it out: Similar to getting the group Id. In your power bi portal, click on the app workspace. Then select the Datasets tab on top. Select the dataset that matches your report (or view Settings) then copy the guid from the url after /datasets/.  Copy that to your code and that should do it. 

View solution in original post

4 REPLIES 4
craigduffy
Regular Visitor

I had the same question. Just figured it out: Similar to getting the group Id. In your power bi portal, click on the app workspace. Then select the Datasets tab on top. Select the dataset that matches your report (or view Settings) then copy the guid from the url after /datasets/.  Copy that to your code and that should do it. 

That's awesome, thanks Craig.

 

If you have it working, would you mind sharing your GenerateToken API syntax?

 

I'm having trouble getting the code provided for the PowerBIEmbedded_AppOwnsData sample to work:

 

var generateTokenRequestParameters = new GenerateTokenRequest("View", null, identities: new List<EffectiveIdentity> { new EffectiveIdentity(username: "username", roles: new List<string> { "roleA", "roleB" }, datasets: new List<string> { "datasetId" }) });

var tokenResponse = await client.Reports.GenerateTokenInGroupAsync("groupId", "reportId", generateTokenRequestParameters);

Like I said, I will only have one role and dataset.  Also, I don't understand why groupID and reportID are in quotes.

 

thanks,

David

I think that where I am getting stuck is how to define the EffectiveIdentity object.  In my code below, there is a squiggly line under it:

 

var generateTokenRequestParameters = new GenerateTokenRequest(
                    accessLevel:  "View", 
                    allowSaveAs: null, 
                    identities: new List<EffectiveIdentity> { new EffectiveIdentity(
                        username: "20", 
                        roles: new List<string> { "User" }, 
                        datasets: new List<string> { "07cf5f83-033d-4265-a9a0-5ba476cde601" }) });
var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(GroupId, "a10024dd-907e-4c1c-baed-e12e0a896d6b", generateTokenRequestParameters);

thanks,

David

Sorry I didn't get notice earlier of your post. Here is my code that works:

 

var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view", identities: new List<EffectiveIdentity> { new EffectiveIdentity(username: userId, roles: new List<string> { role }, datasets: new List<string> { DatasetId }) });

                var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(GroupId, report.Id, generateTokenRequestParameters);

Obviously userId, role, DatasetId and GroupId are string variables. Make sure your role is setup in the Power BI workbook.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors