<?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 Obtain API Token with secure Authentication in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Obtain-API-Token-with-secure-Authentication/m-p/2957760#M40209</link>
    <description>&lt;P&gt;Hello I'm new to Power BI,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to obtain a third party REST API token using Web.Contents, but I want a secure way to do this other than entering a username and password into Power BI.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Saving the username/password to a secured file on a desktop or sharepoint are not ideal solutions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;let&lt;BR /&gt;Details="{""username""****":"",""password"":""****""}",&lt;BR /&gt;Token = Json.Document(Web.Contents("&lt;A href="https://myurl/api/login" target="_blank"&gt;https://myurl/api/login&lt;/A&gt;",[Headers =[#"accept"="*/*",#"Company"="MyCompany",#"Content-Type"="application/json"], Content = Text.ToBinary(Details)]))&lt;BR /&gt;in&lt;BR /&gt;Token&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where **** for username and password are hidden and myurl is the url to login for my specific third party API.&lt;/P&gt;</description>
    <pubDate>Thu, 08 Dec 2022 22:55:57 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-12-08T22:55:57Z</dc:date>
    <item>
      <title>Obtain API Token with secure Authentication</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Obtain-API-Token-with-secure-Authentication/m-p/2957760#M40209</link>
      <description>&lt;P&gt;Hello I'm new to Power BI,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to obtain a third party REST API token using Web.Contents, but I want a secure way to do this other than entering a username and password into Power BI.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Saving the username/password to a secured file on a desktop or sharepoint are not ideal solutions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;let&lt;BR /&gt;Details="{""username""****":"",""password"":""****""}",&lt;BR /&gt;Token = Json.Document(Web.Contents("&lt;A href="https://myurl/api/login" target="_blank"&gt;https://myurl/api/login&lt;/A&gt;",[Headers =[#"accept"="*/*",#"Company"="MyCompany",#"Content-Type"="application/json"], Content = Text.ToBinary(Details)]))&lt;BR /&gt;in&lt;BR /&gt;Token&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where **** for username and password are hidden and myurl is the url to login for my specific third party API.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2022 22:55:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Obtain-API-Token-with-secure-Authentication/m-p/2957760#M40209</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-12-08T22:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain API Token with secure Authentication</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Obtain-API-Token-with-secure-Authentication/m-p/2958658#M40225</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&amp;nbsp;@Anonymous&lt;/a&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please review the following links, hope they can help you.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Using REST API:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/63400612/how-do-i-retrieve-a-bearer-token-from-a-service-in-power-bi" target="_self"&gt;How do I retrieve a bearer token from a service in Power BI?&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&lt;A class="" href="https://community.powerbi.com/t5/Power-Query/Get-token-from-Post-API-call/m-p/2813894" target="_blank" rel="noopener"&gt;Get token from Post API call&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let

url = "https://login.windows.net/xxx/oauth2/v2.0/token",

headers = [#"Content-Type" = "application/x-www-form-urlencoded"],

postData = "grant_type=client_credentials&amp;amp;scope=xxx&amp;amp;client_id=xxx&amp;amp;client_secret=xxx",

response = Web.Contents(

url,

[Headers = headers,

Content = Text.ToBinary(postData)

]

),

JsonResponse=Json.Document(response),

access_token = JsonResponse[access_token]

in

access_token​&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Developer/REST-API-Get-Access-Token/m-p/1895937#:~:text=Every%20portal%20has%20its%20url,or%20your%20account%20and%20password." target="_self"&gt;&lt;SPAN&gt;REST API Get Access Token&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Using Power Automate:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&lt;A class="" href="https://forwardforever.com/how-to-use-service-principal-in-power-bi-admin-rest-api-in-power-automate/" target="_self"&gt;How to use a service principal in Power BI Admin REST APIs in Power Automate&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 09:50:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Obtain-API-Token-with-secure-Authentication/m-p/2958658#M40225</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-12-09T09:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain API Token with secure Authentication</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Obtain-API-Token-with-secure-Authentication/m-p/2959747#M40233</link>
      <description>&lt;P&gt;Thanks for your response&amp;nbsp;@Anonymous&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;This has partially helped me by exploring concepts for service as a principal.&amp;nbsp;&lt;BR /&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/enterprise/read-only-apis-service-principal-authentication" target="_blank"&gt;Enable service principal authentication for read-only admin APIs - Power BI | Microsoft Learn&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, in the example it appears that the code is passing the client ID and client secret, this seems as unsecure as using a username and password.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure if I should be attempting to access the token this way, or in another way described here:&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/power-query/handlingauthentication?source=recommendations" target="_blank"&gt;Handling authentication for Power Query connectors - Power Query | Microsoft Learn&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice is appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 19:34:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Obtain-API-Token-with-secure-Authentication/m-p/2959747#M40233</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-12-09T19:34:45Z</dc:date>
    </item>
  </channel>
</rss>

