Skip to content

Commit 5c81754

Browse files
Fix authentication state revalidation code in project template
1 parent b472b0a commit 5c81754

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/ProjectTemplates/Web.ProjectTemplates/content/RazorComponentsWeb-CSharp/Areas/Identity/RevalidatingAuthenticationStateProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private async Task RevalidationLoop()
6464
{
6565
// Force sign-out. Also stop the revalidation loop, because the user can
6666
// only sign back in by starting a new connection.
67-
var anonymousUser = new ClaimsPrincipal();
67+
var anonymousUser = new ClaimsPrincipal(new ClaimsIdentity());
6868
_currentAuthenticationStateTask = Task.FromResult(new AuthenticationState(anonymousUser));
6969
NotifyAuthenticationStateChanged(_currentAuthenticationStateTask);
7070
_loopCancellationTokenSource.Cancel();

src/ProjectTemplates/Web.ProjectTemplates/content/RazorComponentsWeb-CSharp/Startup.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ public void ConfigureServices(IServiceCollection services)
6767
#endif
6868
services.AddDefaultIdentity<IdentityUser>()
6969
.AddEntityFrameworkStores<ApplicationDbContext>();
70-
71-
services.AddScoped<AuthenticationStateProvider, RevalidatingAuthenticationStateProvider<IdentityUser>>();
7270
#elif (OrganizationalAuth)
7371
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
7472
.AddAzureAD(options => Configuration.Bind("AzureAd", options));
@@ -127,6 +125,9 @@ public void ConfigureServices(IServiceCollection services)
127125
#endif
128126
services.AddRazorPages();
129127
services.AddServerSideBlazor();
128+
#if (IndividualLocalAuth)
129+
services.AddScoped<AuthenticationStateProvider, RevalidatingAuthenticationStateProvider<IdentityUser>>();
130+
#endif
130131
services.AddSingleton<WeatherForecastService>();
131132
}
132133

0 commit comments

Comments
 (0)