C
C#17mo ago
Utsuhoagie

❔ [ASP.Net Core Web API] How to not be forced to add AuthenticationSchemes on actions' [Authorize]

I'm a beginner to ASP.NET Core, I tried following tutorials to set up Identity + JWT authentication and authorization in my current Web API (not minimal) project, and though it works so far with basic login/register, there's one thing bothering me that I haven't found an answer to, in the tutorials or on any SO question. I have to add AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme to the Authorize(...) attribute on every controller action, otherwise they all return a 404 empty result, even with correct authentication + authorization (if any). Is there a way to set this globally in my project? I've tried multiple things suggested online, like manually setting AddAuthentication options (DefaultScheme, DefaultAuthenticationScheme, DefaultChallengeScheme) rather than just passing JwtBearerDefaults.AuthenticationScheme, and checking my ordering of Use... calls, such as making sure UseAuthentication goes before UseAuthorization, though they usually mention UseRouting or UseMvc but my project doesn't have those.
1 Reply
Accord
Accord17mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.