❔ asp.net core auth in endpoint
Hey, I want endpoint that will give null guid to getOffers if user is not auth or if is auth give logged user guid. When I use AllowAnonymous User.Identity.IsAuthenticated is allways null, is there other solution than create one endpoint to get offers for logged user and one for unlogged?
5 Replies
The cleanest way would to be to introduce some kind of authentication middleware
the one that would let the request through, but indicated that it isn't trully authenticated
have u seen it implemented somewhere? is use 2 enpoints in this case (one for logged user and one for unlogged) will be bad practice?
yea, two endpoints is pretty dirty, you should go with middleware
Its pretty straightforward, see if something like this fits you: https://learn.microsoft.com/en-us/aspnet/core/security/authorization/customizingauthorizationmiddlewareresponse?view=aspnetcore-7.0
Customize the behavior of AuthorizationMiddleware
This article explains how to customize the result handling of AuthorizationMiddleware.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.