Skip to content

AuthContext.IsPeerAuthenticated should return true if User.Identity.IsAuthenticated does #2537

Open
@Eagle3386

Description

@Eagle3386

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 returns false, even if context.GetHttpContext().User.Identity.IsAuthenticated returns true.

Since the docs for AuthContext.PeerIdentityPropertyName state:

Gets the name of the property that indicates the peer identity

… I looked at the code which clarified that IsPeerAuthenticated returns true as soon as the former just isn't null - 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 a ClaimsPrincipal with an IIdentity whose IsAuthenticated 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 a ClaimsPrincipal whose IIdentity.IsAuthenticated evaluates to true), can be easily checked/identified via context.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:

  • Calling context.GetHttpContext().User.Identity.IsAuthenticated inside each overwritten method.
  • Using a custom AuthenticationInterceptor which overrides 9 (!) methods to evaluate the IIdentity property & in the event of it being true sort of "modifies" the existing ServerCallContext by cloning everything from it, except for the AuthContext which is replaced with one that has IsPeerAuthenticated return true.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions