<?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: Get the 403 when using auth token authenticate for the PowerBI REST API in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Get-the-403-when-using-auth-token-authenticate-for-the-PowerBI/m-p/2798045#M38899</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="446593" data-lia-user-login="112JKJKSD" class="lia-mention lia-mention-user"&gt;112JKJKSD&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;It's glad to hear that your problem has been resolved. And thanks for sharing your solution here. Could you please mark your post as&amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;Answered&lt;/SPAN&gt;&lt;/STRONG&gt;?&amp;nbsp;It will help the others in the community find the solution &lt;STRONG&gt;&lt;SPAN&gt;easily&lt;/SPAN&gt;&lt;/STRONG&gt; if they face the same problem as yours. &amp;nbsp;Thank you.&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
    <pubDate>Tue, 27 Sep 2022 00:43:07 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-09-27T00:43:07Z</dc:date>
    <item>
      <title>Get the 403 when using auth token authenticate for the PowerBI REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Get-the-403-when-using-auth-token-authenticate-for-the-PowerBI/m-p/2790157#M38849</link>
      <description>&lt;P&gt;I want to use token authenticate for the Power BI REST APIs. Now I have a service principal, then I using the az command line to login in and generate the token:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;az login --service-principal -u ${app_id} -p ${password} --tenant ${tenant_id}

$token= az account get-access-token --query accessToken&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;And it does get the &lt;STRONG&gt;token&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;However, I could not authenticate my power bi server, I got the error 403 Forbidden.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The service principal have the correct rights and add to the workspace access.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In order to verify the permission, I use the source code of a tripartite &lt;A href="https://marketplace.visualstudio.com/items?itemName=maikvandergaag.maikvandergaag-power-bi-actions" target="_self"&gt;extension powerbi action&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And there is function&amp;nbsp;&lt;A href="https://github.com/maikvandergaag/msft-extensions/blob/bc9677d282e011a0c893d4f58000315ba9126a9a/azuredevops/powerbiactions-new/powerbiactionsnew/ps_modules/PowerBi/powerbi.psm1#L269" target="_self"&gt;&lt;STRONG&gt;Invoke-API&lt;/STRONG&gt;&lt;/A&gt;:&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;LI-CODE lang="markup"&gt;Function Invoke-API {
Param(
[parameter(Mandatory = $true)][string]$Url,
[parameter(Mandatory = $true)][string]$Method,
[parameter(Mandatory = $false)][string]$Body,
[parameter(Mandatory = $false)][string]$ContentType
)

$apiHeaders = Get-PowerBIAccessToken

...
}
return $result
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;It is using the&lt;STRONG&gt;&amp;nbsp;Get-PowerBIAccessToken&lt;/STRONG&gt;&amp;nbsp;to get the token.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I using same service principal to connect powerbi service:&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;LI-CODE lang="markup"&gt;$powerbiUrl = 'https://api.powerbi.com/v1.0/myorg'
$sp_secret_key = $Env:sp_secret_key | ConvertTo-SecureString -asPlainText -Force
$organizationType = 'Public'

$cred = New-Object System.Management.Automation.PSCredential($sp_client_id, $sp_secret_key)

Connect-PowerBIServiceAccount -Environment $organizationType -Tenant $sp_tenant_id -Credential $cred -ServicePrincipal


Publish-PowerBIFile -WorkspaceName $target_wrokspace_name -FilePattern "$FilePattern" -Create $Create -Overwrite $Overwrite&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The function&amp;nbsp;&lt;STRONG&gt;Publish-PowerBIFile&lt;/STRONG&gt;&amp;nbsp;will invoke the &lt;STRONG&gt;Invoke-API&lt;/STRONG&gt;. Surprisingly, it worked.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This seems to indicate that my Service Principal has sufficient permissions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;But unfortunately&lt;/STRONG&gt;, the execution of this function calling&amp;nbsp;&lt;STRONG&gt;Connect-PowerBIServiceAccount&lt;/STRONG&gt;&amp;nbsp;requires the installation of the&amp;nbsp;&lt;STRONG&gt;MicrosoftPowerBIMgmt&lt;/STRONG&gt;&amp;nbsp;function module，Our production environment is in a high security environment and &lt;STRONG&gt;does not&lt;/STRONG&gt; allow me to install this module.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I&amp;nbsp;have to generate a token through Service Principal to complete the authentication.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;So my question is&lt;/STRONG&gt;, how is the way I generate the token using Service Principal different from the token generated by&amp;nbsp;Get-PowerBIAccessToken? What should I do to be successful?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;update:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I grab the token through&lt;SPAN&gt;&amp;nbsp;F12&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and use postman to verify the token obtained by&lt;SPAN&gt; F12&amp;nbsp;&lt;/SPAN&gt;and the token obtained by&lt;SPAN&gt; az account get-access-token --query accessToken&lt;/SPAN&gt;, and it is concluded that the token obtained by&lt;SPAN&gt; F12&amp;nbsp;&lt;/SPAN&gt;is valid. So&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;how to generate a valid token through sp or does generating a token require additional permission settings&lt;/STRONG&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2022 17:51:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Get-the-403-when-using-auth-token-authenticate-for-the-PowerBI/m-p/2790157#M38849</guid>
      <dc:creator>112JKJKSD</dc:creator>
      <dc:date>2022-09-23T17:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Get the 403 when using auth token authenticate for the PowerBI REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Get-the-403-when-using-auth-token-authenticate-for-the-PowerBI/m-p/2794869#M38879</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="446593" data-lia-user-login="112JKJKSD" class="lia-mention lia-mention-user"&gt;112JKJKSD&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Please refer the following link to get the token by REST API:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/embed-token/generate-token" target="_self"&gt;Embed Token - Generate Token&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;https://learn.microsoft.com/en-us/rest/api/power-bi/embed-token/generate-token&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And check if it hit any of following &lt;A href="https://learn.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal#considerations-and-limitations" target="_self"&gt;considerations and limitations&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;In addition, the following link had the similar problem as yours. Hope its solution can also help you solve the problem.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/52981450/power-bi-embed-error-403-forbidden-error-from-server" target="_self"&gt;Power BI embed error 403 forbidden error from server&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 03:15:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Get-the-403-when-using-auth-token-authenticate-for-the-PowerBI/m-p/2794869#M38879</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-09-26T03:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: Get the 403 when using auth token authenticate for the PowerBI REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Get-the-403-when-using-auth-token-authenticate-for-the-PowerBI/m-p/2796027#M38888</link>
      <description>&lt;P&gt;Thanks for your reply. I have already check those documents. And I have resolved this issue by adding&amp;nbsp;&amp;nbsp;--resource &lt;A href="https://analysis.windows.net/powerbi/api" target="_blank"&gt;https://analysis.windows.net/powerbi/api&lt;/A&gt;&amp;nbsp;to the az account get-access-token&amp;nbsp;command.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 10:02:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Get-the-403-when-using-auth-token-authenticate-for-the-PowerBI/m-p/2796027#M38888</guid>
      <dc:creator>112JKJKSD</dc:creator>
      <dc:date>2022-09-26T10:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Get the 403 when using auth token authenticate for the PowerBI REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Get-the-403-when-using-auth-token-authenticate-for-the-PowerBI/m-p/2798045#M38899</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="446593" data-lia-user-login="112JKJKSD" class="lia-mention lia-mention-user"&gt;112JKJKSD&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;It's glad to hear that your problem has been resolved. And thanks for sharing your solution here. Could you please mark your post as&amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;Answered&lt;/SPAN&gt;&lt;/STRONG&gt;?&amp;nbsp;It will help the others in the community find the solution &lt;STRONG&gt;&lt;SPAN&gt;easily&lt;/SPAN&gt;&lt;/STRONG&gt; if they face the same problem as yours. &amp;nbsp;Thank you.&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 00:43:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Get-the-403-when-using-auth-token-authenticate-for-the-PowerBI/m-p/2798045#M38899</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-09-27T00:43:07Z</dc:date>
    </item>
  </channel>
</rss>

