When setting up the data protection and Identity, the Identity already needs a built IDataProtectionProvider, while the data protection api doesn't offer this.
ConfigureServices
IDataProtectionBuilder protectionBuilder = services
.AddDataProtection()
.PersistKeysToAzureBlobStorage(storageContainer, "keys.xml");
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
options.Cookies.ApplicationCookie.DataProtectionProvider = //NEEDS AN IDataProtectionProvider
}
For custom cookies it can be set later, in the Configure:
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AutomaticChallenge = false,
ExpireTimeSpan = TimeSpan.FromHours(1),
DataProtectionProvider = app.ApplicationServices.GetService<IDataProtectionProvider>()
});
Relevant docs: https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/compatibility/cookie-sharing