Hello,
We are using OData api of MS Dynamics. Here we are doing authentication using oauth
We are taking reference from
we are using Web Api so we followed below reference.
Steps we have follow :
Ref: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/walkthrough-register-dynamics-365-app-azure-active-directory
2. Acquire token using ADAL.js.
- Tried with ADAL C# sdk but it gets failed as dialog for login window could not pop out into Asp.Net Core Web Api project.
To Generate token we are only using ApplicationId , ResourceUrl (dynamics resource url).
3. Pass as Bearer token to the rest api’s . It worked.
Need : We have to refresh token, if the token get expired. We tried using c# ADAL SDK that is specified into the document itself.
AuthenticationContext authContext =
new AuthenticationContext("https://login.windows.net/common/", false); AuthenticationResult result = await authContext.AcquireTokenAsync(resource, clientId, new Uri(redirectUrl), new PlatformParameters());
Exception : The method or operation is not implemented.
at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Platform.WebUIFactory.CreateAuthenticationDialog(IPlatformParameters parameters)
Can you guide us, how can we refresh token in Web Api (Asp.net Core). And how can we get refresh_token in MS Dynamics OAuth. Do you have any other approach to access token / refresh token?
Note : We only allow login oauth dialog box from html page once and store the given token. We have to use either same token to generate new token or any other way to refresh token(without prompt dialog second time) to be use in MS Dynamics OData Web Api.
We are using Asp.net Core Web API Project to perform interaction between dynamics.
Here is what you can do:
// Everytime you send a request to CRM Web Api, do:
// This basically acquires a token if it is stored in a cache, if it expires it will them try to retrieve another one and start all over again.
AuthenticationResult result = await authContext.AcquireTokenAsync(resource, clientId, new Uri(redirectUrl), new PlatformParameters());
// It is a best practice to refresh the access token before every message request is sent. Doing so
// avoids having to check the expiration date/time of the token. This operation is quick.
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
Hello Vijay,
You can use below method to generate first time token & than refresh token without login again.
result = authContext.AcquireTokenSilentAsync(todoListResourceId, clientId).Result;
You can find sample code for same from below link :
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,902 Super User 2024 Season 2
Martin Dráb 229,297 Most Valuable Professional
nmaenpaa 101,156