Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Web API, generate new Access Token from Refresh Token

Posted on by 5

Hello,

We are using the Web API to access our Dynamics 365 Online CRM.

So far we have been manually generating our Access Token, which gives us a one hour access window.

We have been unable to find the correct series of parameters for programmatically generating a new Access Token from our Refresh Token.

Right now we do not want to use the SDK, ADAL or any other library to achieve this.  Just a basic web call.

Here is an example of how we achieve this at a different site utilizing OAUTH2 security:

WebRequest request = WebRequest.Create("https://accounts.site.com/oauth/v2/token?client_id=<id>&client_secret=<secret>&grant_type=refresh_token&refresh_token=<refresh  token>");
request.Method = "POST";
WebResponse response = request.GetResponse();

Stream dataStream = response.GetResponseStream();

StreamReader reader = new StreamReader(dataStream);

string responseFromServer = reader.ReadToEnd();

reader.Close();

dataStream.Close();

response.Close();

AccessToken at = JsonConvert.DeserializeObject<AccessToken>(responseFromServer);

A very simple POST call using ClientID, ClientSecret and RefreshToken to generate a new AccessToken.  Exactly what I am looking to do in Dynamics 365 API.  But, I cannot find the permutation of parameters that will work in Dynamics to accomplish this.

Has anyone been able to accomplish this with Dynamics 365 Online?

Thanks.

Bryan Hunt

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web API, generate new Access Token from Refresh Token

    Hi Bryan,

    I'm in the same page and looking for the solution.

    Now I've Dynamics 365 online WEB API to access the accounts etc...

    This CRM WEB API + My Wrapper API --> will be in Azure so I can give the API to the third party clients to access on methods

    I'm looking for security purpose so I want to use oAuth2 to generate tokens. So based on token I will allow the methods if Token is matching from the client side. 

    Do you have any idea or post any links that would be really helpful.

    I'm not using Azure AD at all here. 

    Regards,

    Satya

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans