[英]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.aspx和https://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/3799784在https://stackoverflow.com/a/48554845/3799784 中查看我的答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.