0

I have 1 blazor client and 1 SSO server that uses duende identity server. Current project version is .Net7. When accessing blazor's index application link at https://localhost:7244 will automatically redirect the login to my SSO. It works fine. But when I log out at SSO. Blazor client's cookie check also deletes some information like SSO. Logout completed. But blazor client still doesn't redirect to login page automatically. I had to F5 the website again for it to work. Is there a way to automatically navigate to the login page after logged out at SSO ? Here are some of my configurations:

SSO Config in program.cs

builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
                .AddEntityFrameworkStores<BeaconSSOContext>();

builder.Services.AddIdentityServer()
                .AddInMemoryClients(new Client[] {
                    new Client
                    {
                        ClientId = "client",
                        AllowedGrantTypes = GrantTypes.Implicit,
                        RedirectUris = { "https://localhost:7244/signin-oidc" },
                        PostLogoutRedirectUris = { "https://localhost:7244/signout-callback-oidc" },
                        FrontChannelLogoutUri = "https://localhost:7244/signout-oidc",
                        AllowedScopes = { "openid", "profile", "email", "phone" }
                    }
                })
                .AddInMemoryIdentityResources(new IdentityResource[] {
                    new IdentityResources.OpenId(),
                    new IdentityResources.Profile(),
                    new IdentityResources.Email(),
                    new IdentityResources.Phone(),
                })
                .AddAspNetIdentity<IdentityUser>();

Blazor client (program.cs):

// Add services to the container.
builder.Services.AddRazorPages();

builder.Services.AddServerSideBlazor();

builder.Services.AddAuthentication(options =>
{
    options.DefaultScheme = "cookies";
    options.DefaultChallengeScheme = "oidc";
})
.AddCookie("cookies")
.AddOpenIdConnect("oidc", options =>
{
    options.Authority = "https://localhost:7001";
    options.ClientId = "client";
    options.MapInboundClaims = false;
    options.SaveTokens = true;
});

builder.Services.AddAuthorization(options =>
{
    options.FallbackPolicy = new AuthorizationPolicyBuilder()
        .RequireAuthenticatedUser()
        .Build();
});

builder.Services.AddAntDesign();

ConfigurationHelper.Initialize(builder.Configuration);

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}
else
{
    app.UseExceptionHandler("/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseRouting();

app.UseAuthentication();

app.UseAuthorization();

app.MapBlazorHub();

app.MapFallbackToPage("/_Host");

app.Run();

Some solutions that I have tried:

  • Add @attribute [Authorize] to _import.razor
  • Using attribute @attribute [Authorize] at razor page
  • using AuthorizeView and Authorized in mainlayout.razor
Thanh Nguyen
  • 308
  • 3
  • 12

0 Answers0