C
C#2y ago
JUK_Karol

❔ 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
Tinefol
Tinefol2y ago
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
JUK_Karol
JUK_KarolOP2y ago
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?
Tinefol
Tinefol2y ago
yea, two endpoints is pretty dirty, you should go with middleware
Tinefol
Tinefol2y ago
Customize the behavior of AuthorizationMiddleware
This article explains how to customize the result handling of AuthorizationMiddleware.
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server