{"id":9152,"date":"2022-10-12T05:23:18","date_gmt":"2022-10-12T05:23:18","guid":{"rendered":"https:\/\/blogs.aaddevsup.xyz\/?p=9152"},"modified":"2022-10-12T19:30:51","modified_gmt":"2022-10-12T19:30:51","slug":"use-logging-to-troubleshoot-azure-ad-protected-web-api-authentication-or-authorization-errors","status":"publish","type":"post","link":"https:\/\/blogs.aaddevsup.xyz\/2022\/10\/use-logging-to-troubleshoot-azure-ad-protected-web-api-authentication-or-authorization-errors\/","title":{"rendered":"Use logging to troubleshoot Azure AD protected Web API Authentication or Authorization errors"},"content":{"rendered":"\n
The sample web API application in this blog uses .Net 6 Framework and Microsoft.Identity.Web<\/a> nuget package to Azure AD protect the Web API. I use Serilog<\/a> framework for logging the debug output both to the console window and to the local file. This sample assumes you already have a web API application registered in Azure AD. If you are not familiar with how to do that refer to my previous<\/a> blog on the same web API protection topic. To troubleshoot web API Authentication\/Authorization issues, we can take advantage of the following JWTBearerEvents<\/a> to get insight into why a JWT Bearer token might fail to validate: OnTokenValidated, OnMessageReceived, OnAuthenticationFailed, and OnChalleenge events.<\/p>\n\n\n\n Here is how I configure the App ID URI for my Web API<\/p>\n\n\n\n