Fix authentication state revalidation code in project template

This commit is contained in:
Steve Sanderson 2019-06-28 17:28:21 +01:00
parent b472b0afaf
commit 5c81754bad
2 changed files with 4 additions and 3 deletions

View File

@ -64,7 +64,7 @@ namespace RazorComponentsWeb_CSharp.Areas.Identity
{
// Force sign-out. Also stop the revalidation loop, because the user can
// only sign back in by starting a new connection.
var anonymousUser = new ClaimsPrincipal();
var anonymousUser = new ClaimsPrincipal(new ClaimsIdentity());
_currentAuthenticationStateTask = Task.FromResult(new AuthenticationState(anonymousUser));
NotifyAuthenticationStateChanged(_currentAuthenticationStateTask);
_loopCancellationTokenSource.Cancel();

View File

@ -67,8 +67,6 @@ namespace RazorComponentsWeb_CSharp
#endif
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddScoped<AuthenticationStateProvider, RevalidatingAuthenticationStateProvider<IdentityUser>>();
#elif (OrganizationalAuth)
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Configuration.Bind("AzureAd", options));
@ -127,6 +125,9 @@ namespace RazorComponentsWeb_CSharp
#endif
services.AddRazorPages();
services.AddServerSideBlazor();
#if (IndividualLocalAuth)
services.AddScoped<AuthenticationStateProvider, RevalidatingAuthenticationStateProvider<IdentityUser>>();
#endif
services.AddSingleton<WeatherForecastService>();
}