【问题标题】:MS Dynamics : Generate Refresh Token for OAuthMS Dynamics:为 OAuth 生成刷新令牌
【发布时间】:2018-10-20 09:09:42
【问题描述】:

我正在使用 MS Dynamics 的 OData api。这里我们使用 oauth 进行身份验证

我正在参考 参考: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

我正在使用 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 项目中而失败。

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

要生成令牌,我们只使用 ApplicationId 、 ResourceUrl(动态资源 url)。

3。作为 Bearer 令牌传递给其余的 api。它奏效了。

需要:如果令牌过期,我们必须刷新令牌。我们尝试使用在文档本身中指定的 c# ADAL SDK。

   AuthenticationContext authContext =
                new AuthenticationContext("https://login.windows.net/common/", false);

   AuthenticationResult result = await authContext.AcquireTokenAsync(resource, clientId, new Uri(redirectUrl), new PlatformParameters());

异常:方法或操作未实现。

在 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 Project 来执行动态之间的交互。

【问题讨论】:

  • @ArunVinoth 你对此有什么想法吗?你有这方面的样品吗?一点帮助对我来说会很有帮助。
  • 这可能会有所帮助 - stackoverflow.com/q/37535366/7920473

标签: azure dynamics-crm microsoft-dynamics dynamics-365 adal.js


【解决方案1】:

用法:

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-how-to-fix

【讨论】:

    猜你喜欢
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 2017-11-20
    • 2016-03-31
    • 2012-12-21
    • 2015-06-27
    • 2014-08-19
    • 1970-01-01
    相关资源
    最近更新 更多