I'm using ASP.NET Core Identity in my .NET Core 3.1 project and having a hard time figuring out how to persist cookies created from external login providers such as Microsoft or Google across sessions. So far the cookie is always a session cookie and no matter which extension point I've tried, nothing changed that.
Inspecting the source, one could assume that the following approach should work, but it doesn't:
services.AddAuthentication()
.AddMicrosoftAccount(options =>
{
...
options.Events.OnTicketReceived = ctx =>
{
ctx.Properties.IsPersistent = true;
ctx.Properties.ExpiresUtc = DateTime.Now.AddDays(7);
return Task.CompletedTask;
};
});
The event handler gets invoked sucessfully but the .AspNetCore.Identity.Application cookie remains unchanged. I'm pretty sure I'm missing something pretty substantial here - aka digging at the wrong spot :)