<?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 Re: Implementing RLS on Embedded where report token is received by Azure AD REST call. in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Implementing-RLS-on-Embedded-where-report-token-is-received-by/m-p/433718#M13341</link>
    <description>&lt;P&gt;Fixed,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was confused because we were embedding the report through the Azure AD token, I am not sure how to implement RLS through the Azure AD token, like so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; try
            {
                var tokenData = await _authenticationHandler.GetTokenDataAsync();

                using (var client = new PowerBIClient(new Uri(_powerBiSettings.MainAddress), tokenData.tokenCredentials))
                {
                    var report = await client.Reports.GetReportAsync(_powerBiSettings.GroupId, id.ToString());
                    
                    return new ReportDetail
                    {
                        Id = Guid.Parse(report.Id),
                        Name = report.Name,
                        EmbedUrl = report.EmbedUrl,
                        AccessToken = tokenData.accessToken
                    };
                }
            }&lt;/PRE&gt;&lt;P&gt;To fix this we just imbed the power BI report token instead with RLS identity.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;            try
            {
                var tokenData = await _authenticationHandler.GetTokenDataAsync();

                using (var client = new PowerBIClient(new Uri(_powerBiSettings.MainAddress), tokenData.tokenCredentials))
                {
                    var report = await client.Reports.GetReportAsync(_powerBiSettings.GroupId, id.ToString());

                    var identity = new List&amp;lt;EffectiveIdentity&amp;gt;
                    {
                        new EffectiveIdentity("MasterUser", //TODO: Change this to use azure identity
                            roles: new List&amp;lt;string&amp;gt; {"User"},
                            datasets: new List&amp;lt;string&amp;gt; {report.DatasetId})
                    };

                    var generateTokenRequestParameters = new GenerateTokenRequest("view", null, identities: identity);

                    var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(_powerBiSettings.GroupId, report.Id, generateTokenRequestParameters);

                    return new ReportDetail
                    {
                        Id = Guid.Parse(report.Id),
                        Name = report.Name,
                        EmbedUrl = report.EmbedUrl,
                        AccessToken = tokenResponse.Token
                    };
                }
            }&lt;/PRE&gt;&lt;P&gt;Be sure to set the token type to embed rather than AAD token in the Javascript config.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Jun 2018 13:50:19 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-06-06T13:50:19Z</dc:date>
    <item>
      <title>Implementing RLS on Embedded where report token is received by Azure AD REST call.</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Implementing-RLS-on-Embedded-where-report-token-is-received-by/m-p/430453#M13133</link>
      <description>&lt;P&gt;Hello Everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attempting to implement RLS in our .Net Core application of embedding power BI. here is our current TokenDataCall&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        /// &amp;lt;summary&amp;gt;
        /// Gets Token Credentials and access token for use with authenticating PowerBi api calls
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
        public async Task&amp;lt;(TokenCredentials tokenCredentials, string accessToken)&amp;gt; GetTokenDataAsync()
        {
            try
            {
                var authorityUrl = $"{_azureSettings.Instance}{_azureSettings.TenantId}/oauth2/token";

                var oauthEndpoint = new Uri(authorityUrl);

                using (var client = new HttpClient())
                {
                    var result = await client.PostAsync(oauthEndpoint, new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair&amp;lt;string, string&amp;gt;("resource", _powerBiSettings.ResourceAddress),
                        new KeyValuePair&amp;lt;string, string&amp;gt;("client_id", _azureSettings.ClientId),
                        new KeyValuePair&amp;lt;string, string&amp;gt;("grant_type", "password"),
                        new KeyValuePair&amp;lt;string, string&amp;gt;("username", _powerBiSettings.MasterUser),
                        new KeyValuePair&amp;lt;string, string&amp;gt;("password", _powerBiSettings.MasterKey),
                        new KeyValuePair&amp;lt;string, string&amp;gt;("scope", "openid"),
                    }));

                    var content = await result.Content.ReadAsStringAsync();

                    var authenticationResult = JsonConvert.DeserializeObject&amp;lt;OAuthResult&amp;gt;(content);
                    return (new TokenCredentials(authenticationResult.AccessToken, _azureSettings.TokenType), authenticationResult.AccessToken);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                throw;
            }
        }

        private class OAuthResult
        {
            [JsonProperty("token_type")]
            public string TokenType { get; set; }
            [JsonProperty("scope")]
            public string Scope { get; set; }
            [JsonProperty("expires_in")]
            public int ExpiresIn { get; set; }
            [JsonProperty("ext_expires_in")]
            public int ExtExpiresIn { get; set; }
            [JsonProperty("expires_on")]
            public int ExpiresOn { get; set; }
            [JsonProperty("not_before")] 
            public int NotBefore { get; set; }
            [JsonProperty("resource")]
            public Uri Resource { get; set; }
            [JsonProperty("access_token")]
            public string AccessToken { get; set; }
            [JsonProperty("refresh_token")]
            public string RefreshToken { get; set; }
        }&lt;/PRE&gt;&lt;P&gt;I haven't found any documentation on how to use this token call to pass in the "Role" and "username" parameters found here.&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/power-bi/developer/embedded-row-level-security" target="_blank"&gt;https://docs.microsoft.com/en-us/power-bi/developer/embedded-row-level-security&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anyway to add those into the dictionary and for it to return the correct report access token with filtered data?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2018 15:41:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Implementing-RLS-on-Embedded-where-report-token-is-received-by/m-p/430453#M13133</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-06-01T15:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing RLS on Embedded where report token is received by Azure AD REST call.</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Implementing-RLS-on-Embedded-where-report-token-is-received-by/m-p/431477#M13228</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use the Rest API, it could be like below. Please refer to&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/power-bi/developer/embedded-row-level-security#applying-user-and-role-to-an-embed-token" target="_self"&gt;#applying-user-and-role-to-an-embed-token&lt;/A&gt;.&lt;/P&gt;
&lt;PRE&gt;{   
    "accessLevel": "View",
    "identities": [     
        {      
            "username": "EffectiveIdentity",
            "roles": [ "Role1", "Role2" ],
            "datasets": [ "fe0a1aeb-f6a4-4b27-a2d3-b5df3bb28bdc" ]
        }   
    ] 
} &lt;/PRE&gt;
&lt;P&gt;I tested it successfully with Postman.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Implementing RLS on Embedded where report token is received by Azure AD REST call.png" style="width: 600px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/99179i147249934428794E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Implementing RLS on Embedded where report token is received by Azure AD REST call.png" alt="Implementing RLS on Embedded where report token is received by Azure AD REST call.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Dale&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jun 2018 13:51:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Implementing-RLS-on-Embedded-where-report-token-is-received-by/m-p/431477#M13228</guid>
      <dc:creator>v-jiascu-msft</dc:creator>
      <dc:date>2018-06-04T13:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing RLS on Embedded where report token is received by Azure AD REST call.</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Implementing-RLS-on-Embedded-where-report-token-is-received-by/m-p/433718#M13341</link>
      <description>&lt;P&gt;Fixed,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was confused because we were embedding the report through the Azure AD token, I am not sure how to implement RLS through the Azure AD token, like so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; try
            {
                var tokenData = await _authenticationHandler.GetTokenDataAsync();

                using (var client = new PowerBIClient(new Uri(_powerBiSettings.MainAddress), tokenData.tokenCredentials))
                {
                    var report = await client.Reports.GetReportAsync(_powerBiSettings.GroupId, id.ToString());
                    
                    return new ReportDetail
                    {
                        Id = Guid.Parse(report.Id),
                        Name = report.Name,
                        EmbedUrl = report.EmbedUrl,
                        AccessToken = tokenData.accessToken
                    };
                }
            }&lt;/PRE&gt;&lt;P&gt;To fix this we just imbed the power BI report token instead with RLS identity.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;            try
            {
                var tokenData = await _authenticationHandler.GetTokenDataAsync();

                using (var client = new PowerBIClient(new Uri(_powerBiSettings.MainAddress), tokenData.tokenCredentials))
                {
                    var report = await client.Reports.GetReportAsync(_powerBiSettings.GroupId, id.ToString());

                    var identity = new List&amp;lt;EffectiveIdentity&amp;gt;
                    {
                        new EffectiveIdentity("MasterUser", //TODO: Change this to use azure identity
                            roles: new List&amp;lt;string&amp;gt; {"User"},
                            datasets: new List&amp;lt;string&amp;gt; {report.DatasetId})
                    };

                    var generateTokenRequestParameters = new GenerateTokenRequest("view", null, identities: identity);

                    var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(_powerBiSettings.GroupId, report.Id, generateTokenRequestParameters);

                    return new ReportDetail
                    {
                        Id = Guid.Parse(report.Id),
                        Name = report.Name,
                        EmbedUrl = report.EmbedUrl,
                        AccessToken = tokenResponse.Token
                    };
                }
            }&lt;/PRE&gt;&lt;P&gt;Be sure to set the token type to embed rather than AAD token in the Javascript config.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jun 2018 13:50:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Implementing-RLS-on-Embedded-where-report-token-is-received-by/m-p/433718#M13341</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-06-06T13:50:19Z</dc:date>
    </item>
  </channel>
</rss>

