Getting back 401 from Dynamics 365 despite being issued valid token

有些话、适合烂在心里 提交于 2020-03-05 00:35:48

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/60217420/getting-back-401-from-dynamics-365-despite-being-issued-valid-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!