❔ [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.![](https://utfs.io/f/f6765d26-57b7-447a-9ecf-9d9b86f26a2f-1nq2cb.png)
![](https://utfs.io/f/e4146def-7112-4723-bef6-b2362455b999-1nq2cb.png)
![](https://utfs.io/f/cf16c1ed-9e51-47d3-8ca5-0a70e40839f3-1nq2cb.png)
1 Reply
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.