In the article, they refer to CookieValidatePrincipalContextfrom the delegate OnValidatePrincipalin the options CookieAuthenticationEvents.
You need to connect it to functions app.UseCookieAuthenticationin startup.csthis way:
app.UseCookieAuthentication(options =>
{
options.Events = new CookieAuthenticationEvents
{
OnValidatePrincipal = UpdateValidator.ValidateAsync
};
});
And the function UpdateValidatorwill look like this:
public static class UpdateValidator
{
public static async Task ValidateAsync(CookieValidatePrincipalContext context)
{
var newprincipal = new System.Security.Claims.ClaimsPrincipal();
context.ReplacePrincipal(newprincipal);
context.ShouldRenew = true;
}
}
There SecurityStampValidatoris a good example in the class that you can find on github: https://github.com/aspnet/Identity/blob/dev/src/Identity/SecurityStampValidator.cs
source
share