尽管已颁发有效令牌,但仍从 Dynamics 365 取回 401 [英] Getting back 401 from Dynamics 365 despite being issued valid token

查看:19
本文介绍了尽管已颁发有效令牌,但仍从 Dynamics 365 取回 401的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 JavaScript 重写当前连接到 Dynamics 365 的客户端应用

let URL = "https://.operations.dynamics.com/data/FinancialDimensionValues?cross-company=true";让身体 = '';var headers = {'Content-Type':'application/json'};让响应 = ai.https.authorizedRequest(URL, 'GET', body, headers);

目前这个 JavaScript 应用程序可以工作并取回 JSON 数据.我正在尝试使用 C# 重写此应用程序.我首先从 Postman 开始,以确保在继续编写 C# 代码之前我已完成所有身份验证步骤.

使用 Postman,我能够使用客户端凭据"流成功获取 JWT 令牌,在该流中我将客户端 ID 和客户端密钥传递到访问令牌请求 URL.但是,当尝试访问 Dynamics 365 中的 API 端点时,即使我正确传递了 JWT 访问令牌,我也会收到 HTTP 401.

这是访问令牌请求 URL:

https://login.microsoftonline.com/722b0db7-9629-4304-92a0-dfb4a1debe62/oauth2/token?resource=https://<company-domain-here>.dynamics.com

我想我必须正确进行身份验证,否则我将无法取回有效的访问令牌.此外,由于 JavaScript 应用程序已经就位,可以正常工作,我假设 Dynamics 365 已正确配置以允许 API 访问.

我想弄清楚的是我在 Postman 中可能做错了什么导致我收到 401?有效的 JavaScript 请求与我通过 Postman 发送的请求有何不同?

解决方案

问题终于解决了.如前所述,请遵循

参考 帮助我弄清楚的文章.

I am attempting to rewrite a client app that currently connects to Dynamics 365 using JavaScript

let URL = "https://<company-name>.operations.dynamics.com/data/FinancialDimensionValues?cross-company=true";
let  body = '';
var headers = {'Content-Type':'application/json'};
let response = ai.https.authorizedRequest(URL, 'GET', body, headers);

Currently this JavaScript application works and gets back JSON data. I am attempting to rewrite this application using C#. I am first starting with Postman to make sure I have all the authentication steps in place before moving on the writing the C# code.

Using Postman I am able to successfully obtain a JWT token using the "Client Credentials" flow where I pass the Client ID and the Client Secret to the Access Token Request URL. However, when trying to access an API endpoint within Dynamics 365 I receive back an HTTP 401 even though I am passing the JWT access token properly.

Here is the Access Token Request URL:

https://login.microsoftonline.com/722b0db7-9629-4304-92a0-dfb4a1debe62/oauth2/token?resource=https://<company-domain-here>.dynamics.com

I am thinking that I must be authenticating properly or I would not get back a valid access token. Also since the JavaScript application already in place works without issue I am assuming that Dynamics 365 is provisioned properly to allow API access.

What I am trying to figure out is what I might be doing wrong within Postman that results in my receiving a 401? What could be different between the working JavaScript request and what I am sending via Postman?

解决方案

Issue is finally solved. As mentioned follow the documentation mentioned.

If you face 401 Error, here is the last trick.

In postman Under Authorization--> Add authorization data to--> select Request Headers.

Now fire the query you shall have the 200 ok.

Ref Article which helped me figure it out.

这篇关于尽管已颁发有效令牌,但仍从 Dynamics 365 取回 401的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆