【问题标题】:Dynamics CRM 2016 Online Rest API with client credentials OAuth flowDynamics CRM 2016 Online Rest API 与客户端凭据 OAuth 流
【发布时间】:2016-08-27 17:46:47
【问题描述】:

我正在尝试使用 Dynamics CRM 2016 Online 和 Azure Active Directory 进行身份验证。我能够按照这里的所有步骤进行操作:

https://msdn.microsoft.com/en-us/library/mt622431.aspxhttps://msdn.microsoft.com/en-us/library/gg327838.aspx

但这些步骤演示了如何设置用户名身份验证流程。我想使用客户端凭据流。我在 Azure AD 中创建了一个新应用 - 一个 Web 应用程序。我有一个客户端 ID 和一个应用程序密钥,并设置了 Dynamics CRM Online 的权限。我能够获取访问令牌,但在随后的调用中我收到此错误:

HTTP 错误 401 - 未经授权:访问被拒绝

我错过了一个步骤吗?有人知道某处的帖子提供了有关如何使此流程正常工作的详细信息吗?

这是我的代码:

        string clientId = "<client id>";
        string appKey = "<app key>";

        // Get the authority and resource URL at runtime
        AuthenticationParameters ap = AuthenticationParameters.CreateFromResourceUrlAsync(new Uri("https://<org address>/api/data/")).Result;
        String authorityUrl = ap.Authority;
        String resourceUrl = ap.Resource;

        // Authenticate the registered application with Azure Active Directory.
        AuthenticationContext authContext = new AuthenticationContext(authorityUrl);
        ClientCredential clientCredential = new ClientCredential(clientId, appKey);

        AuthenticationResult result = authContext.AcquireToken(resourceUrl, clientCredential);

        HttpClient client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
        HttpResponseMessage response = client.GetAsync("https://<org address>/api/data/v8.1/EntityDefinitions").Result;

【问题讨论】:

标签: azure oauth-2.0 dynamics-crm dynamics-crm-2016


【解决方案1】:

您需要在 CRM 中添加“应用程序用户”并分配自定义安全角色。在https://stackoverflow.com/a/48554845/3799784中查看我的回答

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-19
    • 2017-03-15
    • 1970-01-01
    • 1970-01-01
    • 2019-12-15
    • 2019-12-03
    • 2014-05-04
    相关资源
    最近更新 更多