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

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

问题描述

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

  let URL = https:/ /<公司名称> .operations.dynamics.com / data / FinancialDimensionValues?cross-company = true; 
let body =‘’;
var headers = {’Content-Type’:’application / json’};
let response = ai.https.authorizedRequest(URL, GET,正文,标头);

当前,此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请求与我通过邮递员发送的JavaScript请求之间可能有什么区别?

解决方案

问题终于得到解决。
如前所述,请遵循



参考文章帮助我弄清楚了


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天全站免登陆