Get AuthenticationProperties in ASP.NET 5

In ASP.NET 5 MVC 6 RC1, how can I extract AuthenticationPropertiesfrom a controller or from a filter? HttpContext.Authenticationdoesn't seem to have this feature.

I thought about registering the handler CookieAuthenticationEvents.OnValidatePrincipal, and then using the property Propertiesin the argument CookieValidatePrincipalContext. Then I could store these AuthenticationPropertiesin the query cache, so that later I could get things like IssuedUtc.

Is there a better solution where I don't need to store it?

I do not use the ASP.NET identifier, but the cookie middleware as standalone.

+4
source share
1 answer

ASP.NET 5 , AuthenticateContext:

var context = new AuthenticateContext("[your authentication scheme]");
await HttpContext.Authentication.AuthenticateAsync(context);

if (context.Principal == null || context.Properties == null) {
    throw new InvalidOperationException("The request is not authenticated.");
}

var properties = new AuthenticationProperties(context.Properties);
+4

Source: https://habr.com/ru/post/1622258/


All Articles