【问题标题】:Microsoft Azure access_token not accepted in CRM requestsCRM 请求中不接受 Microsoft Azure access_token
【发布时间】:2017-11-14 11:24:15
【问题描述】:

我正在使用密码授权类型在 IFD 上将 api 与 Dynamics CRM 本地 (v8.1/8.2) 集成在一起。

我正在成功检索访问令牌,但是当我尝试调用端点(例如 /api/data/v8.2/contacts?$select=fullname,contactid )时,我收到 401 - access denied 错误。当我使用该用户登录 CRM 时,我可以成功查看此数据,并且在所有测试的端点上都会出现错误。

有趣的是,今天早上我意识到检索到的令牌无法进行 base64 解码 - 对吗?

我可以使用一些想法来解决问题。我采取的步骤:

  • 三重检查初始令牌请求
  • 三次检查服务根 URL
  • 尝试了两种 CRM/Azure 设置
  • 尝试使用我自己的(节点)代码和互联网示例
  • 各种各样的令牌设置
  • 确认用户存在于 Azure 和 CRM 中
  • 确认用户有足够的权限
  • 已确认 Azure 上的应用程序已授予所有动态权限
  • 确认我与 Azure 和 CRM 在同一个网络中

很明显,我在 Azure 或 CRM 中的某个地方存在配置问题。但是,我找不到任何指南或问题建议查看我尚未检查的问题,我真的可以使用那些不得不对晦涩的设置等进行调整的人的一些意见。

这是我的令牌请求:

var options = {
    method: 'POST',
    url: 'https://login.microsoftonline.com/<snip>/oauth2/token', //for 'intercity technology' (guid is unique)
    headers:
        {
            'cache-control': 'no-cache',
            'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' },
    formData:
        {
            grant_type: 'password',
            client_id: ‘<snip>’, //aplication id
            client_secret: ‘<snip>’, //any key in the keys list
            username: ‘<snip>’,
            password: ‘<snip>’, // and their password
            resource: ‘<snip>’ //application id

        }
};


   logger.debug(util.inspect(options));

    request(options, function (error, response, body) {
...

这是我当前的 api 请求测试:

 var options = {
            method: 'GET',
            url: organisation_url + '/api/data/v8.2/contacts?$select=fullname,contactid',
            headers: {
                Authorization: 'Bearer '+token,
                Accept: 'application/json',
                'OData-MaxVersion':4.0,
                'OData-Version': 4.0,
                'Content-Type': 'application/json; charset=utf-8',
                'Prefer': 'odata.maxpagesize=500',
                'Prefer': 'odata.include-annotations=OData.Community.Display.V1.FormattedValue'
            }
            };
            logger.debug(util.inspect(options));

            request(options, function (error, response, body) {
...

【问题讨论】:

  • 有趣的是,我刚刚找到stackoverflow.com/questions/45467317/…,这与我的情况非常相似。谁能告诉我系统用户在这种情况下指的是什么,(在接受的答案的顶部)。

标签: azure dynamics-crm


【解决方案1】:

您需要使用“client_credentials”而不是“password”的授权类型,因为后者不受支持。 比如:

 grant_type: 'client_credentials',
 client_id: ‘<snip>’, //aplication id
 client_secret: ‘<snip>’, //any key in the keys list
 resource: ‘<snip>’ //CRM Url

按照指南here 和所有链接,确保正确注册 AAD 应用程序并且 CRM 应用程序用户就位。

【讨论】:

  • 那不适合我,我正在使用的动态版本不支持应用程序用户(我相信他们在 2016 版本中被淘汰了)
  • 更正 - 这对我不起作用,因为应用程序用户只存在于动态的云版本而不是本地
猜你喜欢
  • 1970-01-01
  • 2019-04-20
  • 1970-01-01
  • 2017-01-30
  • 1970-01-01
  • 2015-02-15
  • 2016-07-26
  • 2021-11-03
  • 1970-01-01
相关资源
最近更新 更多