Unable to use bearer token to access AAD-secure Web API

人走茶凉 提交于 2019-12-01 10:26:41

I figured out the issue after figuring out how to turn on detailed logging and pouring through them.

Documentation on MSDN says to pass "resource" as the App ID Uri. But you actually need to pass the Client ID as the value for "resource." Once I changed that, everything worked perfectly.

I found this in a txt file in LogFiles\Application.

2016-07-12T15:48:39  PID[8584] Warning     JWT validation failed: IDX10214: Audience validation failed. Audiences: 'https://<removed>.azurewebsites.net'. Did not match:  validationParameters.ValidAudience: '0b61abb8-59...7-6046c22f9c92' or validationParameters.ValidAudiences: 'null'.

Incorrect documentation I was looking at:

https://msdn.microsoft.com/en-us/library/partnercenter/dn974935.aspx https://msdn.microsoft.com/en-us/library/azure/dn645543.aspx (this was the biggest offender as it does exactly what I want to do with incorrect information)

Are you using "UseWindowsAzureActiveDirectoryBearerAuthentication"? In the Web API you should use it, add it in the Startup Config. As following:

app.UseWindowsAzureActiveDirectoryBearerAuthentication( new WindowsAzureActiveDirectoryBearerAuthenticationOptions { Audience = ConfigurationManager.AppSettings["ida:Audience"], Tenant = ConfigurationManager.AppSettings["ida:Tenant"], });

Hope this works for you, Regards!

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