<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Generate filters for a report from c# API based on user in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Generate-filters-for-a-report-from-c-API-based-on-user/m-p/2627742#M37250</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am generating some reports with Azure SQL Direcy Query mode that I will use in my application with the power bi javascript visuals (already implemented). Now, for some reports I need to pre-filter data depending on the user that logs in the application.&lt;BR /&gt;For security reasons using the javascript mode is not the best practice because by default data will be "exposed" for all users and anyone with some javascript knowledges can edit filters and retrieve data that he cannot view.&lt;BR /&gt;Also, users from my application are dynamic and they are a simple username/password, so implementing a RLS from the dataset is not convenient.&lt;BR /&gt;Our application is a multi-tenant application and each tenant can have multiple users from that they can access only data for that they are authorized.&lt;BR /&gt;Is there a mode to create a token from C# Power BI API (I am already using it) with these pre-filters on server side, in order to "mask" the filter and create a true security layer?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;P.S. I was missing my part of code server side:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;var pbiReport = client.Reports.GetReport(groupid, reportid);&lt;/P&gt;&lt;P&gt;EmbedToken embedToken;&lt;BR /&gt;// Create list of dataset&lt;BR /&gt;var datasetIds = new List&amp;lt;Guid&amp;gt;();&lt;/P&gt;&lt;P&gt;// Add dataset associated to the report&lt;BR /&gt;datasetIds.Add(Guid.Parse(pbiReport.DatasetId));&lt;/P&gt;&lt;P&gt;// Append additional dataset to the list to achieve dynamic binding later&lt;BR /&gt;datasetIds.Add(Guid.Parse("correctdatasource"));&lt;/P&gt;&lt;P&gt;// Get Embed token multiple resources&lt;BR /&gt;var tokenRequest = new GenerateTokenRequestV2(&lt;BR /&gt;reports: new List&amp;lt;GenerateTokenRequestV2Report&amp;gt;() { new GenerateTokenRequestV2Report(reportid) },&lt;BR /&gt;datasets: datasetIds.Select(datasetId =&amp;gt; new GenerateTokenRequestV2Dataset(datasetId.ToString())).ToList(),&lt;BR /&gt;targetWorkspaces: groupid != Guid.Empty ? new List&amp;lt;GenerateTokenRequestV2TargetWorkspace&amp;gt;() {&lt;BR /&gt;new GenerateTokenRequestV2TargetWorkspace(groupid)&lt;BR /&gt;} : null&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;// Generate Embed token&lt;BR /&gt;embedToken = client.EmbedToken.GenerateToken(tokenRequest);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;I was thinking also to implement RLS on my database, but this is not a solution because I need to create credentials for each user (I can do that) and change dataset credentials per user while accessing report (probably cannot)&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jul 2022 13:36:46 GMT</pubDate>
    <dc:creator>ms92ita</dc:creator>
    <dc:date>2022-07-08T13:36:46Z</dc:date>
    <item>
      <title>Generate filters for a report from c# API based on user</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Generate-filters-for-a-report-from-c-API-based-on-user/m-p/2627742#M37250</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am generating some reports with Azure SQL Direcy Query mode that I will use in my application with the power bi javascript visuals (already implemented). Now, for some reports I need to pre-filter data depending on the user that logs in the application.&lt;BR /&gt;For security reasons using the javascript mode is not the best practice because by default data will be "exposed" for all users and anyone with some javascript knowledges can edit filters and retrieve data that he cannot view.&lt;BR /&gt;Also, users from my application are dynamic and they are a simple username/password, so implementing a RLS from the dataset is not convenient.&lt;BR /&gt;Our application is a multi-tenant application and each tenant can have multiple users from that they can access only data for that they are authorized.&lt;BR /&gt;Is there a mode to create a token from C# Power BI API (I am already using it) with these pre-filters on server side, in order to "mask" the filter and create a true security layer?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;P.S. I was missing my part of code server side:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;var pbiReport = client.Reports.GetReport(groupid, reportid);&lt;/P&gt;&lt;P&gt;EmbedToken embedToken;&lt;BR /&gt;// Create list of dataset&lt;BR /&gt;var datasetIds = new List&amp;lt;Guid&amp;gt;();&lt;/P&gt;&lt;P&gt;// Add dataset associated to the report&lt;BR /&gt;datasetIds.Add(Guid.Parse(pbiReport.DatasetId));&lt;/P&gt;&lt;P&gt;// Append additional dataset to the list to achieve dynamic binding later&lt;BR /&gt;datasetIds.Add(Guid.Parse("correctdatasource"));&lt;/P&gt;&lt;P&gt;// Get Embed token multiple resources&lt;BR /&gt;var tokenRequest = new GenerateTokenRequestV2(&lt;BR /&gt;reports: new List&amp;lt;GenerateTokenRequestV2Report&amp;gt;() { new GenerateTokenRequestV2Report(reportid) },&lt;BR /&gt;datasets: datasetIds.Select(datasetId =&amp;gt; new GenerateTokenRequestV2Dataset(datasetId.ToString())).ToList(),&lt;BR /&gt;targetWorkspaces: groupid != Guid.Empty ? new List&amp;lt;GenerateTokenRequestV2TargetWorkspace&amp;gt;() {&lt;BR /&gt;new GenerateTokenRequestV2TargetWorkspace(groupid)&lt;BR /&gt;} : null&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;// Generate Embed token&lt;BR /&gt;embedToken = client.EmbedToken.GenerateToken(tokenRequest);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;I was thinking also to implement RLS on my database, but this is not a solution because I need to create credentials for each user (I can do that) and change dataset credentials per user while accessing report (probably cannot)&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 13:36:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Generate-filters-for-a-report-from-c-API-based-on-user/m-p/2627742#M37250</guid>
      <dc:creator>ms92ita</dc:creator>
      <dc:date>2022-07-08T13:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Generate filters for a report from c# API based on user</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Generate-filters-for-a-report-from-c-API-based-on-user/m-p/2630495#M37279</link>
      <description>&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;HI&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="387570" data-lia-user-login="ms92ita" class="lia-mention lia-mention-user"&gt;ms92ita&lt;/a&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;I think RLS based on username should be more suitable for your requirements. &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;You only need to create a mapping table with username and recorders and link to other table records and assign roles on the power bi service side. (it can be assigned to a group) &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Then these filter effects will be dynamically applied to your dataset when the report data is loaded.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;&lt;A href="https://community.powerbi.com/t5/Desktop/RLS-with-UserName/m-p/82327" target="_blank"&gt;Solved: RLS with UserName() - Microsoft Power BI Community&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;In addition, if you do not want to add a detailed user mapping table to your data source, you also need to compare user mapping in your code.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;You can add a tag field to your table field, then use the if statement in your code to compare the current username and default user list to return the tag and manually apply the filter effect based on the result.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Xiaoxin Sheng&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2022 09:33:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Generate-filters-for-a-report-from-c-API-based-on-user/m-p/2630495#M37279</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-07-11T09:33:11Z</dc:date>
    </item>
  </channel>
</rss>

