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 AuthenticationContext.AcquireTokenByRefreshToken.
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?
protected void Page_Load(object sender, EventArgs e)
{
//Redirect uri must match the redirect_uri used when requesting Authorization code.
string redirectUri = String.Format("{0}Redirect", Properties.Settings.Default.RedirectUrl);
string authorityUri = Properties.Settings.Default.AADAuthorityUri;
// Get the auth code
string code = Request.Params.GetValues(0)[0];
// Get auth token from auth code
TokenCache TC = new TokenCache();
AuthenticationContext AC = new AuthenticationContext(authorityUri, TC);
ClientCredential cc = new ClientCredential
(Properties.Settings.Default.ClientID,
Properties.Settings.Default.ClientSecret);
AuthenticationResult AR = AC.AcquireTokenByAuthorizationCode(code, new Uri(redirectUri), cc);
//Set Session "authResult" index string to the AuthenticationResult
Session[_Default.authResultString] = AR;
//Redirect back to Default.aspx
Response.Redirect("/Default.aspx");
}
Thanks.