MS Dynamics:为OAuth生成刷新令牌 [英] MS Dynamics : Generate Refresh Token for OAuth

查看:106
本文介绍了MS Dynamics:为OAuth生成刷新令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MS Dynamics的OData api.在这里,我们使用oauth

进行身份验证

我正在参考 参考: https://docs.microsoft.com/zh-cn/dynamics365/customer-engagement/developer/developer-guide?view=dynamics-ce-odata-9

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

我正在使用Web Api,因此我们遵循以下参考.

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

我们遵循的步骤:

1 .将应用程序注册到Microsoft Azure:

参考: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/walkthrough-register-dynamics-365-app-azure-active-directory

2 .使用ADAL.js获取令牌. -尝试使用ADAL C#sdk,但由于登录窗口对话框无法弹出到Asp.Net Core Web Api项目中而失败.

Ref:

异常:该方法或操作未实现.

在 Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Platform.WebUIFactory.CreateAuthenticationDialog(IPlatformParameters 参数)

您能指导我们如何在Web Api(Asp.net Core)中刷新令牌.以及如何在MS Dynamics OAuth中获取refresh_token.您还有其他访问令牌/刷新令牌的方法吗?

注意:我们只允许一次从html页面登录oauth对话框并存储给定的令牌.我们必须使用相同的令牌来生成新令牌,或者使用其他任何方式来刷新令牌(第二次不出现提示对话框),以便在MS Dynamics OData Web Api中使用. 我正在使用Asp.net Core Web API项目在动力学之间进行交互.

解决方案

用法:

AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(ClientConfig.CRMOrgUrl,clientcred).结果

参考:

https://community.dynamics.com/crm/b/gustafscrmblog/archive/2017/09/15/authenticationresult-acquiretoken-deprecated-in-adal-3-x-and -如何修复

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.

解决方案

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

这篇关于MS Dynamics:为OAuth生成刷新令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆