Forum Discussion
rishabhshukla12
9 years agoNew Member
PBIWebAPP C# Refresh Token
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 ...
Eric_Zhang
9 years agoMicrosoft Employee
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 AAD forum. Just for your reference, Configurable token lifetimes in Azure Active Directory (Public Preview).
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.
Also, please note the the refreshtoken and AcquireTokenByRefreshToken seems no longer exposed in ADAL 3.0 or newer. For further questions, please go to the AAD forum as well.
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;
}
ahnaja
7 years agoRegular Visitor
What Microsoft.IdentityModel.Clients.ActiveDirectory version are you using?