web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Is it possible to request a new AccessToken by passing a Refresh Token using AuthenticationContext class in C#?

(0) ShareShare
ReportReport
Posted on by 792

Hello everyone,

I have followed the Client sample code section in this page https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/data-entities/services-home-page#authentication to generate AccessToken for use in calling OData services.

Code snippet:-

UriBuilder uri = new UriBuilder ("login.windows.net/contoso2ax.onmicrosoft.com");
string aadClientAppId = "someappid";

AuthenticationContext authenticationContext = new AuthenticationContext(uri.ToString());

var userCredential = new UserPasswordCredential(username, password);
authenticationResult = authenticationContext.AcquireTokenAsync("usnconeboxaos.cloud.dynamics.com", aadClientAppId, userCredential).Result; 

string authenticationHeader = authenticationResult.CreateAuthorizationHeader();

But these AccessTokens are short-lived and expires after 30mins. So I was requesting a new AccessToken everytime it expires (basically calling this same snippet of above code). 

But now I learnt that there is a concept of refresh tokens, passing which you can renew your access token. I have also gone through this blog https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code. But I want to know whether there is any way to renew access token using refresh token  through AuthenticationContext APIs?

And also, which one of these 2 methods better? Renewing AccessToken by calling the above code snippet every time, or using Refresh token?

Thanks.

*This post is locked for comments

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 26

#2
imran ul haq Profile Picture

imran ul haq 8

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 4 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans