- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在向 Dynamics CRM 2016 Web API 发出 HTTP GET 请求以进行概念验证时遇到问题。
我已关注this walk-through创建在 Azure Active Directory 上设置的 Multi-Tenancy Web 应用程序,该应用程序已被授予以组织用户身份访问 Dynamics CRM 的权限。
我用了this example code为了获得访问 token 。这似乎有效,为我提供了看起来像有效 token 的内容。
我使用 token 执行了一个简单的 GET 请求,该请求失败并显示 401 Unauthorized
。代码:
class Test
{
public async Task RunAsync()
{
var resource = "https://<snip>.crm4.dynamics.com/api/data/v8.1/";
var authParams = AuthenticationParameters.CreateFromResourceUrlAsync(new Uri(resource))
.Result;
var authorityUrl = authParams.Authority;
var resourceUrl = authParams.Resource;
var clientId = "<snip>";
var client_secret = "<snip>";
var clientCredential = new ClientCredential(clientId, client_secret);
var authContext = new AuthenticationContext(authorityUrl, false);
var token = authContext.AcquireToken(resourceUrl, clientCredential);
var response = await CallApiAsync($"{resourceUrl}api/data/v8.1/accounts?$select=name&$top=3", token.AccessToken);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(response.RequestMessage);
Console.WriteLine(response.Headers);
Console.WriteLine(response.ReasonPhrase);
Console.WriteLine(content);
}
private async Task<HttpResponseMessage> CallApiAsync(string uri, string token)
{
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", token);
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");
return await httpClient.GetAsync(uri);
}
}
}
请求:
Method: GET, RequestUri: 'https://<snip>.crm4.dynamics.com/api/data/v8.1/accounts?$select=name&$top=3', Version: 1.1, Content: <null>, Headers:
{
Authorization: Bearer <snip>
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
}
回应:
REQ_ID: <snip>
Strict-Transport-Security: max-age=31536000; includeSubDomains
Date: Tue, 21 Feb 2017 15:08:39 GMT
Set-Cookie: crmf5cookie=<snip>;secure; path=/
Server: Microsoft-IIS/8.5
WWW-Authenticate: Bearer authorization_uri=https://login.windows.net/<snip>/oauth2/authorize,resource_id=https://<snip>.crm4.dynamics.com/
X-Powered-By: ASP.NET
Unauthorized
HTTP Error 401 - Unauthorized: Access is denied
我觉得我错过了一些明显的东西?
最佳答案
没有正在使用的 CRM 组织用户。看看这个Server to Server Auth教程。您需要创建一个应用程序用户。这里有更多关于 Tip of the Day for Server to Server Auth 的评论.
在服务器到服务器身份验证之外,您可以 authenticate as a CRM user using creds this way .
关于c# - Dynamics CRM Web api 401 获取 Oauth token 后未经授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42393395/
据我所知,要将声音设置为铃声,应将其插入 MediaStore。在 MediaStore 中写入,需要 WRITE_EXTERNAL_STORAGE 权限。但是...有没有办法在不需要 WRITE_E
我只是想设置铃声。我不想授予 WRITE_SETTINGS 权限,我可以找到大部分答案来授予 WRITE_SETTINGS 权限但是我正在使用一个应用程序,该应用程序没有设置铃声的 WRITE_SET
我在 Windows 10 中以管理员身份运行 Android studio。AVD 是 Nexus 5X API 28。我正在尝试运行 flutter 演示,但设备下拉框仍然显示“无设备”,它只是有
我的应用程序构建于 spring-social-twitter允许用户使用 Twitter 登录的功能最近已停止工作。 我收到如下错误消息: Callback URL not approved for
我正在尝试使用 python-firebase 更新 Firebase库,但无法使用经过修改的示例代码进行身份验证: from firebase import firebase as fb auth
今天,当我尝试使用 GCC7 编译一个非常简单的 C++ 程序时,我遇到了一个非常奇怪的问题:程序没有向构造函数中的 vector 添加任何元素,当编译时没有优化(例如 -O0/-Og ) 来自 Re
简单问题:我正在尝试使用 Discord API 备份服务器(或公会,如果您使用官方术语)上的所有消息。 因此,我实现了 OAuth,没有任何问题,我有访问 token ,并且可以查询一些端点(我尝试
您好,我正在使用 msdn 中的以下代码供我公司内部使用: using System; public sealed class Singleton { private static volati
我们从 Google 的 GCM 服务中收到间歇性的 401 Unauthorized 错误。在过去,它 100% 的时间都有效。该问题可能与我们的路由器接受 IPv6 流量同时发生,但即使我们在适配
我有一个使用 Playwright + TS-Jest 设置 E2E 测试的项目。为了组织我的测试,我使用页面对象模型。结构看起来像这样: 我想在 tsconfig.json 中使用 TypeScri
我有一个后端应用程序在 Google Cloud Storage 中同步文件,我想在 javascript 中列出存储中的所有文件,而不需要从后端请求它们。我已经设置了 CORS,并且所有文件的 ac
我在尝试在私有(private) gitlab 存储库中发布 Artifact 时遇到问题。我正在使用 Maven 并使用个人访问 token 进行身份验证。当我运行 mvn deploy -s ~/
这是从 Google+ 登录中使用的 GoogleApiClient 获取 token 的传统方式: String token = GoogleAuthUtil.getToken(apiClient.
我在阅读 facebook Open Graph 文档后比较确定我不能让网站“订阅”公共(public)页面,除非该页面安装了我的应用程序。如果那是错误的,请告诉我。 我想做的是一个照片库,非常简单,
我是一名优秀的程序员,十分优秀!