<?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: Can't Authenticate against login microsoft online to generate bearer token in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Can-t-Authenticate-against-login-microsoft-online-to-generate/m-p/2393689#M34966</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/275884"&gt;@v-henryk-mstf&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've used your code as example and it generated a token sucessfully. Although, When I try to use the token to list my workspaces (groups), the API reply with a "Forbiden" error message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my code following your example (some variables were omitted for securety behalf):&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-inline" image-alt="trt18sistemas_0-1647304626114.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/684057i3502F5BF9C94A6B9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="trt18sistemas_0-1647304626114.png" alt="trt18sistemas_0-1647304626114.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the output:&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-inline" image-alt="trt18sistemas_1-1647304738439.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/684058iE812EADF708765A5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="trt18sistemas_1-1647304738439.png" alt="trt18sistemas_1-1647304738439.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To make sure that it's not some issue on Power BI, I've tried the same on Postman and, as in Powe BI, I could generate a token, but when I try to query the list of workspaces&amp;nbsp; a "403 Forbidden" message is replied.&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-inline" image-alt="trt18sistemas_2-1647304896414.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/684059iEC964E2AA013A611/image-size/medium?v=v2&amp;amp;px=400" role="button" title="trt18sistemas_2-1647304896414.png" alt="trt18sistemas_2-1647304896414.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For some reason that I don't know why, the tokens generated by Azure AD doesn't seems to work with Power BI.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Mar 2022 00:43:56 GMT</pubDate>
    <dc:creator>trt18-sistemas</dc:creator>
    <dc:date>2022-03-15T00:43:56Z</dc:date>
    <item>
      <title>Can't Authenticate against login microsoft online to generate bearer token</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Can-t-Authenticate-against-login-microsoft-online-to-generate/m-p/2386314#M34869</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm following these videos tutorials (part 1: &lt;A href="https://youtu.be/fjzmz0BNN_g" target="_blank" rel="noopener"&gt;https://youtu.be/fjzmz0BNN_g&lt;/A&gt;&amp;nbsp;and part 2: &lt;A href="https://youtu.be/N8qYRSqRz84)" target="_blank" rel="noopener"&gt;https://youtu.be/N8qYRSqRz84)&lt;/A&gt;&amp;nbsp;and almost everything is running fine. I can create the app (directly at azure portal as these video seems to be a little bit old), connect to the REST API and list groups/workspaces. But when I try to generate the Bearer token authenticating with my Power BI user, I get the following error message:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;"It was not possible to authenticate using the provided credentials. Try again".&lt;/EM&gt;&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-inline" image-alt="trt18sistemas_0-1646915855628.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/682167iBC4C4866239676EE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="trt18sistemas_0-1646915855628.png" alt="trt18sistemas_0-1646915855628.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;(&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to replace the username and password by "App Secret Id" and "App Secret Value", but the error message &lt;EM&gt;"Query error. DataSource.Error: Web.Contents fail to get the content of "&lt;A href="https://login.microsoftonline.com/commom/oauth2/token/" target="_blank" rel="noopener"&gt;https://login.microsoftonline.com/commom/oauth2/token/&lt;/A&gt;" (400): Bad Request. Detaisl: ..."&lt;/EM&gt; (image bellow) was launched.&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-inline" image-alt="trt18sistemas_1-1646915980550.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/682168iF068AD194F17741B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="trt18sistemas_1-1646915980550.png" alt="trt18sistemas_1-1646915980550.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anybody help me understand what is going wrong and how to solve this problem?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;function GerarToken&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;() =&amp;gt;
let
    username = USER,
    pwd = PASSWORD,
    body = "grant_type=Password&amp;amp;resource=https://analysis.windows.net/powerbi/api&amp;amp;client_id=APP_ID_CLIENT&amp;amp;username="&amp;amp;username&amp;amp;"&amp;amp;password="&amp;amp;pwd,
    Data=Json.Document(Web.Contents("https://login.microsoftonline.com/common/oauth2/token/", [Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(body)])),
    access_token = Data[access_token]
in
    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;Query to List Groups&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;let
    token = GerarToken(),
    Source = Json.Document(Web.Contents("https://api.powerbi.com/v1.0/myorg/groups?$top=100", [Headers=[Authorization="Bearer " &amp;amp; token]])),
    value = Source[value],
    #"Converted to Table" = Table.FromList(value, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "isReadOnly", "isOnDedicatedCapacity", "name"}, {"id", "isReadOnly", "isOnDedicatedCapacity", "name"})
in
    #"Expanded Column1"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 13:23:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Can-t-Authenticate-against-login-microsoft-online-to-generate/m-p/2386314#M34869</guid>
      <dc:creator>trt18-sistemas</dc:creator>
      <dc:date>2022-03-10T13:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: Can't Authenticate against login microsoft online to generate bearer token</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Can-t-Authenticate-against-login-microsoft-online-to-generate/m-p/2390688#M34932</link>
      <description>&lt;P&gt;One more info. I tried the same thing by using Postman online and it worked, but using Powe BI the autentication error message continues.&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-inline" image-alt="trt18sistemas_0-1647203438773.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/683319i9C6C90E92503327D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="trt18sistemas_0-1647203438773.png" alt="trt18sistemas_0-1647203438773.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would be greatefull for any help.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Mar 2022 20:31:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Can-t-Authenticate-against-login-microsoft-online-to-generate/m-p/2390688#M34932</guid>
      <dc:creator>trt18-sistemas</dc:creator>
      <dc:date>2022-03-13T20:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Can't Authenticate against login microsoft online to generate bearer token</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Can-t-Authenticate-against-login-microsoft-online-to-generate/m-p/2391837#M34950</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/174813"&gt;@trt18-sistemas&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try to use following M query code if they help with you scenario:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let

url = "https://login.microsoftonline.com/xxxxxxx/oauth2/token",

GetJson =

Web.Contents(

url,

[

Headers = [

Accept = "application/json",

ContentType = "application/x-www-form-urlencoded"

],

Content =

Text.ToBinary(

"grant_type=client_credentials&amp;amp;

client_id=xxxxxxx&amp;amp;

client_secret=xxxxxxx&amp;amp;

scope=xxxxxx"

)

]

),

token = Json.Document(GetJson)[access_token],

Result =

Web.Contents(

"https://xxxxx.xxx.com",

[

Headers = [

#"Content-Type" = "application/json",

Authorization = "Bearer " + token,

RelativePath = "/xxxxx/xxxxx"

]

]

)

in

Result&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Xiaoxin Sheng&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 09:19:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Can-t-Authenticate-against-login-microsoft-online-to-generate/m-p/2391837#M34950</guid>
      <dc:creator>v-henryk-mstf</dc:creator>
      <dc:date>2022-03-14T09:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: Can't Authenticate against login microsoft online to generate bearer token</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Can-t-Authenticate-against-login-microsoft-online-to-generate/m-p/2393689#M34966</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/275884"&gt;@v-henryk-mstf&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've used your code as example and it generated a token sucessfully. Although, When I try to use the token to list my workspaces (groups), the API reply with a "Forbiden" error message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my code following your example (some variables were omitted for securety behalf):&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-inline" image-alt="trt18sistemas_0-1647304626114.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/684057i3502F5BF9C94A6B9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="trt18sistemas_0-1647304626114.png" alt="trt18sistemas_0-1647304626114.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the output:&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-inline" image-alt="trt18sistemas_1-1647304738439.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/684058iE812EADF708765A5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="trt18sistemas_1-1647304738439.png" alt="trt18sistemas_1-1647304738439.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To make sure that it's not some issue on Power BI, I've tried the same on Postman and, as in Powe BI, I could generate a token, but when I try to query the list of workspaces&amp;nbsp; a "403 Forbidden" message is replied.&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-inline" image-alt="trt18sistemas_2-1647304896414.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/684059iEC964E2AA013A611/image-size/medium?v=v2&amp;amp;px=400" role="button" title="trt18sistemas_2-1647304896414.png" alt="trt18sistemas_2-1647304896414.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For some reason that I don't know why, the tokens generated by Azure AD doesn't seems to work with Power BI.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 00:43:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Can-t-Authenticate-against-login-microsoft-online-to-generate/m-p/2393689#M34966</guid>
      <dc:creator>trt18-sistemas</dc:creator>
      <dc:date>2022-03-15T00:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: Can't Authenticate against login microsoft online to generate bearer token</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Can-t-Authenticate-against-login-microsoft-online-to-generate/m-p/2444535#M35406</link>
      <description>&lt;P&gt;Replying here the solution found.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As posting above, the &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/275884"&gt;@v-henryk-mstf&lt;/a&gt; suggestion works to generate the bearer token. After using its example code, another error occurred. It was happening because, for some reason, the permission to use API, accessible at "Administration Portal &amp;gt;&amp;gt; Tenant Configuration &amp;gt;&amp;gt; Allow principal services to use Power BI&amp;nbsp; API", must be set as "All organization" (yellow highlighted), instead of "Specific groups" (red underlined).&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-inline" image-alt="trt18sistemas_0-1649378099071.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/696703i65CA72AD7F8F3D02/image-size/medium?v=v2&amp;amp;px=400" role="button" title="trt18sistemas_0-1649378099071.png" alt="trt18sistemas_0-1649378099071.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2022 00:37:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Can-t-Authenticate-against-login-microsoft-online-to-generate/m-p/2444535#M35406</guid>
      <dc:creator>trt18-sistemas</dc:creator>
      <dc:date>2022-04-08T00:37:44Z</dc:date>
    </item>
  </channel>
</rss>

