C
C#13mo 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
Tinefol13mo 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_Karol13mo 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
Tinefol13mo ago
yea, two endpoints is pretty dirty, you should go with middleware
Tinefol
Tinefol13mo ago
Customize the behavior of AuthorizationMiddleware
This article explains how to customize the result handling of AuthorizationMiddleware.
Accord
Accord13mo 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.