<?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 Trying to get a MS refresh token for Power BI REST API authentication in PowerShell in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Trying-to-get-a-MS-refresh-token-for-Power-BI-REST-API/m-p/4200675#M56628</link>
    <description>&lt;P&gt;We are using some power bi automation PowerShell script which is using a refresh token. It was working fine on the old server, but we try to migrate this script to another server. On this new server we need once a refresh token. How can I get the refresh token of a specific user account for login page of Exchange (&lt;A href="https://outlook.office365.com/" rel="nofollow noreferrer" target="_blank"&gt;https://outlook.office365.com&lt;/A&gt;)? In the technical documentation of this solution I read that I need to do it by fiddler, but I dont see the refresh token in the response header.&lt;/P&gt;&lt;P&gt;See below the powershell script which needs the refresh token:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;$refresh_token_securestring = Get-Content "F:\scripts\PowerBI\ExchangeOnlineRefreshAccessToken.txt" | ConvertTo-SecureString

$refresh_token_BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($refresh_token_securestring)
$refresh_token = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($refresh_token_BSTR)
Remove-Variable refresh_token_securestring
Remove-Variable refresh_token_BSTR

# Request Access token with refresh token 

$resourceID = "https://outlook.office365.com"
$tenant_id = "MyTenantGuid"
$clientId = "MyClientIdGuid"
$uri = "https://login.microsoftonline.com/${tenant_id}/oauth2/token"
$body = @{grant_type='refresh_token';resource=$resourceID;client_id=$client_id;refresh_token=$refresh_token}
$tokenresult = Invoke-RestMethod -Method Post -Uri $uri -Body $body&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Sep 2024 12:56:14 GMT</pubDate>
    <dc:creator>khha</dc:creator>
    <dc:date>2024-09-30T12:56:14Z</dc:date>
    <item>
      <title>Trying to get a MS refresh token for Power BI REST API authentication in PowerShell</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Trying-to-get-a-MS-refresh-token-for-Power-BI-REST-API/m-p/4200675#M56628</link>
      <description>&lt;P&gt;We are using some power bi automation PowerShell script which is using a refresh token. It was working fine on the old server, but we try to migrate this script to another server. On this new server we need once a refresh token. How can I get the refresh token of a specific user account for login page of Exchange (&lt;A href="https://outlook.office365.com/" rel="nofollow noreferrer" target="_blank"&gt;https://outlook.office365.com&lt;/A&gt;)? In the technical documentation of this solution I read that I need to do it by fiddler, but I dont see the refresh token in the response header.&lt;/P&gt;&lt;P&gt;See below the powershell script which needs the refresh token:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;$refresh_token_securestring = Get-Content "F:\scripts\PowerBI\ExchangeOnlineRefreshAccessToken.txt" | ConvertTo-SecureString

$refresh_token_BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($refresh_token_securestring)
$refresh_token = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($refresh_token_BSTR)
Remove-Variable refresh_token_securestring
Remove-Variable refresh_token_BSTR

# Request Access token with refresh token 

$resourceID = "https://outlook.office365.com"
$tenant_id = "MyTenantGuid"
$clientId = "MyClientIdGuid"
$uri = "https://login.microsoftonline.com/${tenant_id}/oauth2/token"
$body = @{grant_type='refresh_token';resource=$resourceID;client_id=$client_id;refresh_token=$refresh_token}
$tokenresult = Invoke-RestMethod -Method Post -Uri $uri -Body $body&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 12:56:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Trying-to-get-a-MS-refresh-token-for-Power-BI-REST-API/m-p/4200675#M56628</guid>
      <dc:creator>khha</dc:creator>
      <dc:date>2024-09-30T12:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get a MS refresh token for Power BI REST API authentication in PowerShell</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Trying-to-get-a-MS-refresh-token-for-Power-BI-REST-API/m-p/4201509#M56673</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/816283"&gt;@khha&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ResourceID might be the issue. Have you tried it with the ResourceID =&amp;nbsp;&lt;A href="https://graph.microsoft.com/" target="_blank"&gt;https://graph.microsoft.com/&lt;/A&gt;&amp;nbsp;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here a blog article, that helps you identifying ResourceIDs / AudienceURLs:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.tackytech.blog/how-to-effectively-determine-the-token-resource-url-sometimes-also-referred-to-as-audience-or-scope-for-authentication/" target="_blank"&gt;https://www.tackytech.blog/how-to-effectively-determine-the-token-resource-url-sometimes-also-referred-to-as-audience-or-scope-for-authentication/&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;/Tom&lt;BR /&gt;&lt;A href="https://www.tackytech.blog/" target="_blank"&gt;https://www.tackytech.blog/&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://www.instagram.com/tackytechtom/" target="_blank"&gt;https://www.instagram.com/tackytechtom/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 15:14:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Trying-to-get-a-MS-refresh-token-for-Power-BI-REST-API/m-p/4201509#M56673</guid>
      <dc:creator>tackytechtom</dc:creator>
      <dc:date>2024-09-30T15:14:43Z</dc:date>
    </item>
  </channel>
</rss>

