简体   繁体   English

Dynamics CRM 2016 Online Rest API 与客户端凭据 OAuth 流

[英]Dynamics CRM 2016 Online Rest API with client credentials OAuth flow

I'm trying to authenticate with Dynamics CRM 2016 Online and Azure Active Directory.我正在尝试使用 Dynamics CRM 2016 Online 和 Azure Active Directory 进行身份验证。 I was able to follow all the steps here:我能够按照这里的所有步骤进行操作:

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

but these steps demonstrate how to set-up username authentication flow.但这些步骤演示了如何设置用户名身份验证流程。 I would like to use the client credentials flow.我想使用客户端凭据流。 I created a new app in Azure AD - a web application.我在 Azure AD 中创建了一个新应用程序 - 一个 Web 应用程序。 I have a client ID and an app key and I set-up the permissions for Dynamics CRM Online.我有一个客户端 ID 和一个应用程序密钥,我为 Dynamics CRM Online 设置了权限。 I'm able to get the access token, but on subsequent calls I get this error:我能够获得访问令牌,但在随后的调用中我收到此错误:

HTTP Error 401 - Unauthorized: Access is denied HTTP 错误 401 - 未经授权:访问被拒绝

Is there a step I missed?有没有我错过的一步? Does anybody know of a post somewhere that provides details on how to get this flow working?有人知道某处的帖子提供了有关如何使此流程正常工作的详细信息吗?

Here is my code:这是我的代码:

        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;

You need to add an "Application user" and assign a custom Security Role in CRM.您需要在 CRM 中添加“应用程序用户”并分配自定义安全角色。 See my answer in https://stackoverflow.com/a/48554845/3799784https://stackoverflow.com/a/48554845/3799784 中查看我的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以使用azure oauth2客户端凭据流访问经典的azure服务管理rest api吗? - can i use azure oauth2 client credentials flow to access the classic azure service management rest api? 自定义系统与Crm Dynamics 2016 Online之间的集成 - Integration between custom system and Crm Dynamics 2016 Online 邮递员未使用Oauth客户端凭据连接到Dynamics365 API,控制台应用程序使用相同的详细信息 - Postman not connecting to Dynamics365 API using Oauth client credentials, console app working using same details Azure AD OAuth 客户端凭据授予流程 - Azure AD OAuth Client Credentials Grant flow 适用于Java的CRM Dynamics Online 2016 Azure SDK接收带有500错误代码的BrokeredMessages - CRM Dynamics Online 2016 Azure SDK for Java receive BrokeredMessages with 500 error code 获取Oauth令牌后未经授权的Dynamics CRM Web API 401 - Dynamics CRM web api 401 Unauthorized after obtaining Oauth token 使用REST API从Dynamics CRM导入数据 - Import data from dynamics CRM using REST API Microsoft Dynamics CRM OAuth集成 - Microsoft Dynamics CRM OAuth Integration 用于业务认证客户端凭据流oAuth 2.0的onedrive - onedrive for business authentication client credentials flow oAuth 2.0 Azure AD OAuth 令牌错误的受众(客户端凭据流) - Azure AD OAuth token wrong audience (client credentials flow)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM