<?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 Errors authenticating with a Public Client Application in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Errors-authenticating-with-a-Public-Client-Application/m-p/4103010#M54787</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm learning how to use the Power BI REST API. I am using the MSAL library to authenticate my desktop application, and I am using the below function to create a bearer token:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def getBearerToken():
    client_id = os.environ.get("CLIENT_ID")
    client_secret = os.environ.get("CLIENT_SECRET")
    tenant_id = os.environ.get("TENANT_ID")
    scope = ['https://analysis.windows.net/powerbi/api/.default']
    authority_url = "https://login.microsoftonline.com/" + tenant_id


    app = msal.PublicClientApplication(client_id, authority=authority_url)
    response = app.acquire_token_interactive(scopes=scope, port=5000)

    return response['access_token']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am successfully creating a bearer token after logging in with my account. However, when I try to run a simple API call, I keep getting a 401 error. Below is the API call I am making:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;token = getBearerToken()
endpoint = "https://api.powerbi.com/v1.0/myorg/groups"

headers = {"Content-type": "application/json", "Authorization": f"Bearer {token}"}

r = requests.get(endpoint, headers=headers)

print(r.status_code)
print(r.content)&lt;/LI-CODE&gt;&lt;P&gt;Instead of getting the workspaces I am in, I instead get a 401 error with nothing inside the response body. Any ideas what I need to change in the Azure Portal, or my API calls?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Taha&lt;/P&gt;</description>
    <pubDate>Thu, 15 Aug 2024 20:40:53 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-08-15T20:40:53Z</dc:date>
    <item>
      <title>Errors authenticating with a Public Client Application</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Errors-authenticating-with-a-Public-Client-Application/m-p/4103010#M54787</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm learning how to use the Power BI REST API. I am using the MSAL library to authenticate my desktop application, and I am using the below function to create a bearer token:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def getBearerToken():
    client_id = os.environ.get("CLIENT_ID")
    client_secret = os.environ.get("CLIENT_SECRET")
    tenant_id = os.environ.get("TENANT_ID")
    scope = ['https://analysis.windows.net/powerbi/api/.default']
    authority_url = "https://login.microsoftonline.com/" + tenant_id


    app = msal.PublicClientApplication(client_id, authority=authority_url)
    response = app.acquire_token_interactive(scopes=scope, port=5000)

    return response['access_token']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am successfully creating a bearer token after logging in with my account. However, when I try to run a simple API call, I keep getting a 401 error. Below is the API call I am making:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;token = getBearerToken()
endpoint = "https://api.powerbi.com/v1.0/myorg/groups"

headers = {"Content-type": "application/json", "Authorization": f"Bearer {token}"}

r = requests.get(endpoint, headers=headers)

print(r.status_code)
print(r.content)&lt;/LI-CODE&gt;&lt;P&gt;Instead of getting the workspaces I am in, I instead get a 401 error with nothing inside the response body. Any ideas what I need to change in the Azure Portal, or my API calls?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Taha&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2024 20:40:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Errors-authenticating-with-a-Public-Client-Application/m-p/4103010#M54787</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-08-15T20:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Errors authenticating with a Public Client Application</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Errors-authenticating-with-a-Public-Client-Application/m-p/4103673#M54795</link>
      <description>&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Hi,&amp;nbsp;@Anonymous&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Regarding the issue you raised, my solution is as follows:&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial;"&gt;&lt;SPAN&gt;1.&lt;/SPAN&gt;&lt;SPAN&gt;First, check the permissions: Make sure you have the correct permissions assigned to the application in the Azure portal. You'll need to give your application permission to Read and write everything in the Power BI service.&lt;BR /&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vlinyulumsft_0-1723789894701.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1152081iD47451AF1BAA09F0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vlinyulumsft_0-1723789894701.png" alt="vlinyulumsft_0-1723789894701.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;&lt;SPAN&gt;2.&lt;/SPAN&gt;&lt;SPAN&gt;Second, you can try to validate the token first: make sure that the token you get contains the correct permissions. You can use tools like JWT.io to decode the token and check the permission claims in it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;" lang="zh-CN"&gt;The following documents are what we hope will help you:&lt;/P&gt;
&lt;P style="margin: 0in;"&gt;&lt;A href="https://jwt.io/introduction/" target="_blank"&gt;&lt;SPAN&gt;JSON Web Token Introduction - jwt.io&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Of course, if you have any new ideas, you are welcome to contact us.&lt;BR /&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Best Regards,&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;Leroy Lu&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Arial; font-size: 12.0pt; color: black;"&gt;If this post &lt;SPAN&gt;helps&lt;/SPAN&gt;, then please consider Accept it &lt;SPAN&gt;as the solution &lt;/SPAN&gt;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 06:32:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Errors-authenticating-with-a-Public-Client-Application/m-p/4103673#M54795</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-08-16T06:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Errors authenticating with a Public Client Application</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Errors-authenticating-with-a-Public-Client-Application/m-p/4111736#M54891</link>
      <description>&lt;P&gt;I realized that I needed to specify the actual scopes of the application, rather than leaving it at default. Once I did that, everything authenticated as expected.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 16:43:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Errors-authenticating-with-a-Public-Client-Application/m-p/4111736#M54891</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-08-21T16:43:47Z</dc:date>
    </item>
  </channel>
</rss>

