<?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: PBIWebAPP C#  Refresh Token in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/PBIWebAPP-C-Refresh-Token/m-p/199096#M6350</link>
    <description>&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/33307"&gt;@rishabhshukla12&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Regarding extend the liftertime of access token, it is an Azure AD question, to get a bettere response, I'd suggest your post in the dedicated &lt;A href="https://social.msdn.microsoft.com/Forums/azure/en-US/home?forum=WindowsAzureAD" target="_self"&gt;AAD forum&lt;/A&gt;. Just for your reference, &lt;A href="https://docs.microsoft.com/en-us/azure/active-directory/active-directory-configurable-token-lifetimes" target="_self"&gt;Configurable token lifetimes in Azure Active Directory (Public Preview)&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to how to get accesstoken with refresh token, you could reference below sample. It is for demo purpose, you don't have to get a new refreshtoken every time, the refreshtoken by default lives for 14 days, according to the above link.&lt;/P&gt;
&lt;P&gt;Also, please note the the refreshtoken and&amp;nbsp;AcquireTokenByRefreshToken seems&amp;nbsp;no longer exposed in ADAL 3.0 or newer. &amp;nbsp;For further questions, please go to the AAD forum as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        public string GetAccessToken(string authorizationCode, string clientID, string clientSecret, string redirectUri)
        {
            //Redirect uri must match the redirect_uri used when requesting Authorization code.
            //Note: If you use a redirect back to Default, as in this sample, you need to add a forward slash
            //such as http://localhost:13526/

            // Get auth token from auth code       
            TokenCache TC = new TokenCache();

            //Values are hard-coded for sample purposes
            string authority = Properties.Settings.Default.AADAuthorityUri;
            AuthenticationContext AC = new AuthenticationContext(authority, TC);
            ClientCredential cc = new ClientCredential(clientID, clientSecret);

            //Set token from authentication result

            string refreshtoken = AC.AcquireTokenByAuthorizationCode(
                 authorizationCode,
                 new Uri(redirectUri), cc).RefreshToken;

           return AC.AcquireTokenByRefreshToken(refreshtoke, cc, "https://analysis.windows.net/powerbi/api").AccessToken; 
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 22 Jun 2017 07:09:35 GMT</pubDate>
    <dc:creator>Eric_Zhang</dc:creator>
    <dc:date>2017-06-22T07:09:35Z</dc:date>
    <item>
      <title>PBIWebAPP C#  Refresh Token</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/PBIWebAPP-C-Refresh-Token/m-p/196884#M6318</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Is there anyone who could tell me how to use the refresh token to get a new token. I am using PBIWebAPP dashboard code available on GitHub. I am a beginner in C# and don't know much about the how to use&amp;nbsp;AuthenticationContext.AcquireTokenByRefreshToken.&lt;/SPAN&gt;&lt;/P&gt;&lt;H1&gt;&amp;nbsp;&lt;/H1&gt;&lt;P&gt;The code I am using to generate the access token, which is getting expired in 1 hours. Can anyone help to put refresh token method so that I don't have to manually run this code again and again to get the new access token. Also, how can I extend the expiry time of the token?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;protected void Page_Load(object sender, EventArgs e)&lt;BR /&gt;{&lt;BR /&gt;//Redirect uri must match the redirect_uri used when requesting Authorization code.&lt;BR /&gt;string redirectUri = String.Format("{0}Redirect", Properties.Settings.Default.RedirectUrl);&lt;BR /&gt;string authorityUri = Properties.Settings.Default.AADAuthorityUri;&lt;/P&gt;&lt;P&gt;// Get the auth code&lt;BR /&gt;string code = Request.Params.GetValues(0)[0];&lt;/P&gt;&lt;P&gt;// Get auth token from auth code&lt;BR /&gt;TokenCache TC = new TokenCache();&lt;/P&gt;&lt;P&gt;AuthenticationContext AC = new AuthenticationContext(authorityUri, TC);&lt;BR /&gt;ClientCredential cc = new ClientCredential&lt;BR /&gt;(Properties.Settings.Default.ClientID,&lt;BR /&gt;Properties.Settings.Default.ClientSecret);&lt;/P&gt;&lt;P&gt;&amp;nbsp;AuthenticationResult AR = AC.AcquireTokenByAuthorizationCode(code, new Uri(redirectUri), cc);&lt;/P&gt;&lt;P&gt;//Set Session "authResult" index string to the AuthenticationResult&lt;BR /&gt;Session[_Default.authResultString] = AR;&lt;/P&gt;&lt;P&gt;//Redirect back to Default.aspx&lt;BR /&gt;Response.Redirect("/Default.aspx");&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 18:03:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/PBIWebAPP-C-Refresh-Token/m-p/196884#M6318</guid>
      <dc:creator>rishabhshukla12</dc:creator>
      <dc:date>2017-06-19T18:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: PBIWebAPP C#  Refresh Token</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/PBIWebAPP-C-Refresh-Token/m-p/199096#M6350</link>
      <description>&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/33307"&gt;@rishabhshukla12&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Regarding extend the liftertime of access token, it is an Azure AD question, to get a bettere response, I'd suggest your post in the dedicated &lt;A href="https://social.msdn.microsoft.com/Forums/azure/en-US/home?forum=WindowsAzureAD" target="_self"&gt;AAD forum&lt;/A&gt;. Just for your reference, &lt;A href="https://docs.microsoft.com/en-us/azure/active-directory/active-directory-configurable-token-lifetimes" target="_self"&gt;Configurable token lifetimes in Azure Active Directory (Public Preview)&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to how to get accesstoken with refresh token, you could reference below sample. It is for demo purpose, you don't have to get a new refreshtoken every time, the refreshtoken by default lives for 14 days, according to the above link.&lt;/P&gt;
&lt;P&gt;Also, please note the the refreshtoken and&amp;nbsp;AcquireTokenByRefreshToken seems&amp;nbsp;no longer exposed in ADAL 3.0 or newer. &amp;nbsp;For further questions, please go to the AAD forum as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        public string GetAccessToken(string authorizationCode, string clientID, string clientSecret, string redirectUri)
        {
            //Redirect uri must match the redirect_uri used when requesting Authorization code.
            //Note: If you use a redirect back to Default, as in this sample, you need to add a forward slash
            //such as http://localhost:13526/

            // Get auth token from auth code       
            TokenCache TC = new TokenCache();

            //Values are hard-coded for sample purposes
            string authority = Properties.Settings.Default.AADAuthorityUri;
            AuthenticationContext AC = new AuthenticationContext(authority, TC);
            ClientCredential cc = new ClientCredential(clientID, clientSecret);

            //Set token from authentication result

            string refreshtoken = AC.AcquireTokenByAuthorizationCode(
                 authorizationCode,
                 new Uri(redirectUri), cc).RefreshToken;

           return AC.AcquireTokenByRefreshToken(refreshtoke, cc, "https://analysis.windows.net/powerbi/api").AccessToken; 
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 07:09:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/PBIWebAPP-C-Refresh-Token/m-p/199096#M6350</guid>
      <dc:creator>Eric_Zhang</dc:creator>
      <dc:date>2017-06-22T07:09:35Z</dc:date>
    </item>
    <item>
      <title>Re: PBIWebAPP C#  Refresh Token</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/PBIWebAPP-C-Refresh-Token/m-p/573884#M17733</link>
      <description>&lt;P&gt;What Microsoft.IdentityModel.Clients.ActiveDirectory version are you using?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 19:55:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/PBIWebAPP-C-Refresh-Token/m-p/573884#M17733</guid>
      <dc:creator>ahnaja</dc:creator>
      <dc:date>2018-11-27T19:55:41Z</dc:date>
    </item>
  </channel>
</rss>

