<?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 Api report custom header add role in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Api-report-custom-header-add-role/m-p/267345#M8128</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;  public async Task&amp;lt;ActionResult&amp;gt; GetReportEmbedded()
        {
            // Create a user password credentials.
            var accessToken = await GetTokenCredentials();

            var tokenCredentials = new TokenCredentials(accessToken, "Bearer");

            // Generate Embed Token.

            //using (FileStream fileStream = new FileStream(powerBi.Value.pbixPath, FileMode.Open, FileAccess.Read))
            using (var client = new PowerBIClient(new Uri(powerBi.Value.ApiUrl), tokenCredentials))
            using (Task&amp;lt;Group&amp;gt; tableTalkGroup = client.Groups.GetGroupsWithHttpMessagesAsync()
                .ContinueWith(task =&amp;gt; task.Result.Body.Value.First(group =&amp;gt; @group.Name == "*** group name ***")))
            using (Task&amp;lt;Report&amp;gt; reportTask = client.Reports.GetReportsInGroupWithHttpMessagesAsync((await tableTalkGroup).Id).ContinueWith(task =&amp;gt; task.Result.Body.Value.First(report =&amp;gt; report.Name == "Power BI Template")))

            {
                Dictionary&amp;lt;string, List&amp;lt;string&amp;gt;&amp;gt; headerDictionary = new Dictionary&amp;lt;string, List&amp;lt;string&amp;gt;&amp;gt;();
                headerDictionary.Add("roles", new List&amp;lt;string&amp;gt;{ "***custom role***" });

                var tokenResponse = await client.Reports.GenerateTokenInGroupWithHttpMessagesAsync(
                    (await tableTalkGroup).Id, (await reportTask).Id, new GenerateTokenRequest(accessLevel: "view"),
                    headerDictionary, CancellationToken.None);
                // Generate Embed Configuration.
                var embedConfig = new EmbedConfig()
                {
                    EmbedToken = tokenResponse.Body,
                    EmbedUrl = (await reportTask).EmbedUrl,
                    Id = (await reportTask).Id
                };

                return View(embedConfig);
            }
        }&lt;/PRE&gt;&lt;P&gt;i have uploaded a pbix file with custom role now i am trying to apply this role to the embedded report but i don't&amp;nbsp;know how to add&amp;nbsp;the custom&amp;nbsp;header properly to add my request for the&amp;nbsp;role. the ONLY reference i could find to this is here&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-ca/azure/power-bi-workspace-collections/app-token-flow&amp;nbsp;" target="_blank"&gt;https://docs.microsoft.com/en-ca/azure/power-bi-workspace-collections/app-token-flow&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but it references&amp;nbsp;the deprecated&amp;nbsp;"&lt;SPAN&gt;Power BI Workspace Collections". i keep seeing the customHeader Parameter in a lot of the calls i use but i don't&amp;nbsp;know how to properly use it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;i am trying to use this for my company's multi tenant solution and i want make sure customers only have access to their data. i think im going about this in the right direction but if not please let me know.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Oct 2017 21:29:24 GMT</pubDate>
    <dc:creator>Mexicoder</dc:creator>
    <dc:date>2017-10-03T21:29:24Z</dc:date>
    <item>
      <title>Api report custom header add role</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Api-report-custom-header-add-role/m-p/267345#M8128</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;  public async Task&amp;lt;ActionResult&amp;gt; GetReportEmbedded()
        {
            // Create a user password credentials.
            var accessToken = await GetTokenCredentials();

            var tokenCredentials = new TokenCredentials(accessToken, "Bearer");

            // Generate Embed Token.

            //using (FileStream fileStream = new FileStream(powerBi.Value.pbixPath, FileMode.Open, FileAccess.Read))
            using (var client = new PowerBIClient(new Uri(powerBi.Value.ApiUrl), tokenCredentials))
            using (Task&amp;lt;Group&amp;gt; tableTalkGroup = client.Groups.GetGroupsWithHttpMessagesAsync()
                .ContinueWith(task =&amp;gt; task.Result.Body.Value.First(group =&amp;gt; @group.Name == "*** group name ***")))
            using (Task&amp;lt;Report&amp;gt; reportTask = client.Reports.GetReportsInGroupWithHttpMessagesAsync((await tableTalkGroup).Id).ContinueWith(task =&amp;gt; task.Result.Body.Value.First(report =&amp;gt; report.Name == "Power BI Template")))

            {
                Dictionary&amp;lt;string, List&amp;lt;string&amp;gt;&amp;gt; headerDictionary = new Dictionary&amp;lt;string, List&amp;lt;string&amp;gt;&amp;gt;();
                headerDictionary.Add("roles", new List&amp;lt;string&amp;gt;{ "***custom role***" });

                var tokenResponse = await client.Reports.GenerateTokenInGroupWithHttpMessagesAsync(
                    (await tableTalkGroup).Id, (await reportTask).Id, new GenerateTokenRequest(accessLevel: "view"),
                    headerDictionary, CancellationToken.None);
                // Generate Embed Configuration.
                var embedConfig = new EmbedConfig()
                {
                    EmbedToken = tokenResponse.Body,
                    EmbedUrl = (await reportTask).EmbedUrl,
                    Id = (await reportTask).Id
                };

                return View(embedConfig);
            }
        }&lt;/PRE&gt;&lt;P&gt;i have uploaded a pbix file with custom role now i am trying to apply this role to the embedded report but i don't&amp;nbsp;know how to add&amp;nbsp;the custom&amp;nbsp;header properly to add my request for the&amp;nbsp;role. the ONLY reference i could find to this is here&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-ca/azure/power-bi-workspace-collections/app-token-flow&amp;nbsp;" target="_blank"&gt;https://docs.microsoft.com/en-ca/azure/power-bi-workspace-collections/app-token-flow&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but it references&amp;nbsp;the deprecated&amp;nbsp;"&lt;SPAN&gt;Power BI Workspace Collections". i keep seeing the customHeader Parameter in a lot of the calls i use but i don't&amp;nbsp;know how to properly use it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;i am trying to use this for my company's multi tenant solution and i want make sure customers only have access to their data. i think im going about this in the right direction but if not please let me know.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 21:29:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Api-report-custom-header-add-role/m-p/267345#M8128</guid>
      <dc:creator>Mexicoder</dc:creator>
      <dc:date>2017-10-03T21:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: Api report custom header add role</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Api-report-custom-header-add-role/m-p/268363#M8154</link>
      <description>&lt;P&gt;so i still dont know how to use custom header but i figured ouut how to add roles using the&amp;nbsp;GenerateTokenRequest object and the&amp;nbsp;GenerateTokenInGroupWithHttpMessagesAsync call.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    private async Task&amp;lt;string&amp;gt; GetTokenCredentials()
        {
            var credential = new UserPasswordCredential(powerBi.Value.Username, powerBi.Value.Password);

            // Authenticate using created credentials
            var authenticationContext = new AuthenticationContext(powerBi.Value.AuthorityUrl);
            var authenticationResult =
                await authenticationContext.AcquireTokenAsync(powerBi.Value.ResourceUrl, powerBi.Value.ClientId,
                    credential);

            if (authenticationResult == null)
            {
                Console.WriteLine("Authentication Failed");
                return string.Empty;
            }
            return authenticationResult.AccessToken;
        }



        public async Task&amp;lt;ActionResult&amp;gt; GetReportEmbedded()
        {
            // Create a user password credentials.
            var accessToken = await GetTokenCredentials();

            var tokenCredentials = new TokenCredentials(accessToken, "Bearer");

            // Generate Embed Token.

            using (var client = new PowerBIClient(new Uri(powerBi.Value.ApiUrl), tokenCredentials))
            using (Task&amp;lt;Group&amp;gt; tableTalkGroup = client.Groups.GetGroupsWithHttpMessagesAsync()
                .ContinueWith(task =&amp;gt; task.Result.Body.Value.First(group =&amp;gt; @group.Name == "Tuku TEST")))
            using (Task&amp;lt;Report&amp;gt; reportTask = client.Reports.GetReportsInGroupWithHttpMessagesAsync((await tableTalkGroup).Id).ContinueWith(task =&amp;gt; task.Result.Body.Value.First(report =&amp;gt; report.Name == "DirectQueryPC")))

            {
                var generateTokenRequestParameters = new GenerateTokenRequest(
                    accessLevel: "View",
                    datasetId: null,
                    identities: new List&amp;lt;EffectiveIdentity&amp;gt;
                    {
                        new EffectiveIdentity(
                            username: powerBi.Value.Username,
                            roles: new List&amp;lt;string&amp;gt; { "filterKel" },
                            datasets: new List&amp;lt;string&amp;gt; { (await reportTask).DatasetId })
                    });

                var tokenResponse = await client.Reports.GenerateTokenInGroupWithHttpMessagesAsync(
                    groupId: (await tableTalkGroup).Id,
                    reportKey: (await reportTask).Id,
                    requestParameters: generateTokenRequestParameters);
                // Generate Embed Configuration.
                var embedConfig = new EmbedConfig()
                {
                    EmbedToken = tokenResponse.Body,
                    EmbedUrl = (await reportTask).EmbedUrl,
                    Id = (await reportTask).Id
                };

                return View(embedConfig);
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2017 20:39:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Api-report-custom-header-add-role/m-p/268363#M8154</guid>
      <dc:creator>Mexicoder</dc:creator>
      <dc:date>2017-10-04T20:39:20Z</dc:date>
    </item>
  </channel>
</rss>

