AuthContext.IsPeerAuthenticated
should return true if User.Identity.IsAuthenticated
does
#2537
Labels
enhancement
New feature or request
Is your feature request related to a problem? Please describe.
After loads of trial & error (no offense, but some docs are confusing for beginners), it seems my Blazor WASM standalone app authenticates Azure B2C users via MSAL correctly - except for 1 thing:
context.AuthContext.IsPeerAuthenticated
always returnsfalse
, even ifcontext.GetHttpContext().User.Identity.IsAuthenticated
returnstrue
.Since the docs for
AuthContext.PeerIdentityPropertyName
state:… I looked at the code which clarified that
IsPeerAuthenticated
returnstrue
as soon as the former just isn'tnull
- but that doesn't always seem to get set properly.From what I could find (mainly 2 unit tests in this repo), the C# implementation solely focuses on authentication via certificates, because if the underlying
HttpContext
contains aClaimsPrincipal
with anIIdentity
whoseIsAuthenticated
is true, gRPC seems to "simply not care".Describe the solution you'd like
Please, for Padawan-like developers like me, i.e., those struggling with authentication & authorization, enable that authenticated users (= those with an
HttpContext
containing aClaimsPrincipal
whoseIIdentity.IsAuthenticated
evaluates totrue
), can be easily checked/identified viacontext.AuthContext.IsPeerAuthenticated
, too.Because otherwise
context.GetHttpContext()
needs to be called on each & every method call.Describe alternatives you've considered
Continuing to use either workaround:
context.GetHttpContext().User.Identity.IsAuthenticated
inside each overwritten method.AuthenticationInterceptor
which overrides 9 (!) methods to evaluate theIIdentity
property & in the event of it beingtrue
sort of "modifies" the existingServerCallContext
by cloning everything from it, except for theAuthContext
which is replaced with one that hasIsPeerAuthenticated
returntrue
.Additional context
The docs regarding
AuthContext
should be improved to make its content as well as usage clearer - maybe even by adding a usage example for the scenario I just described.The text was updated successfully, but these errors were encountered: