Forum Discussion
Custom USERPRINCIPALNAME() when consumming API through Service Principal
- 3 years ago
It took me a long time before being able to figure out the best solution.
Using service principal was not the best approach in order to take the user's rights in account.
So I had to focus on the other way (more complicated for novice as I am) to embed reports, based on user's scope delegation located in the Azure application.
Hi Lauger
If you are embedding reports that contain RLS in the dataset then you need to generate the embedToken along with EffectiveIdentity element in the request. There you specify the username and roles to be passed for a dataset containing RLS, which in turn can be retrieved in Power BI report either by USERNAME() or USERPRINCIPALNAME() functions. These can be used in the roles setup to construct the proper filtering condition in DAX.
Please refer to the below Power BI REST API documentation to get the details on how to construct the body of token request:
https://learn.microsoft.com/en-us/rest/api/power-bi/embed-token/generate-token
and specifically this part related to EffectiveIdentity should be what you need:
https://learn.microsoft.com/en-us/rest/api/power-bi/embed-token/generate-token#effectiveidentity
Hope that helps!
Best regards,
Andrzej