401 when authenticating an OAuth 2.0 bearer token with Microsoft Azure Active Directory in an MVC API

只谈情不闲聊 提交于 2019-12-05 05:29:46

It seems that I can get it to work by creating a second application in AD - a client app, authorizing it to the service app, and requesting the authentication token as the client rather than as the service.

So in the token request I had to use the client app's ID and secret instead of the original ones and add another parameter: "resource", whose value is the service app ID: https://mytenant.onmicrosoft.com/servieappname

I based my solution on this good example by Microsoft. Replaced the Windows store app by a web app acting as the client.

Barton KIng

I added the following attribute to the controller directing it to use the specific authentication filter.

[HostAuthentication("Bearer")]
public class someController:ApiController{
}

Change your TestController so it derives from ApiController instead of Controller.

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