MS Dynamics : Generate Refresh Token for OAuth

北战南征 提交于 2019-12-24 17:43:30

问题


I am using OData api of MS Dynamics. Here we are doing authentication using oauth

I am taking reference from Ref : https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/developer-guide?view=dynamics-ce-odata-9

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/connect-customer-engagement-web-services-using-oauth

I am using Web Api so we followed below reference.

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/oauth-cross-origin-resource-sharing-connect-single-page-application

Steps we have follow :

1. Registered an app to Microsoft Azure:

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.

Ref : https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/connect-customer-engagement-web-services-using-oauth

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. I am using Asp.net Core Web API Project to perform interaction between dynamics.


回答1:


Usage:

AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(ClientConfig.CRMOrgUrl, clientcred).Result;

Reference:

https://community.dynamics.com/crm/b/gustafscrmblog/archive/2017/09/15/authenticationresult-acquiretoken-deprecated-in-adal-3-x-and-how-to-fix



来源:https://stackoverflow.com/questions/50267093/ms-dynamics-generate-refresh-token-for-oauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!