C#C
C#3y ago
Hrolgar

❔ Troubleshooting Blazor Server Authentication with Duende IdentityServer: Need Help and Insights!

Hello everyone! 👋

I've successfully set up a Duende IdentityServer that works seamlessly with Asp.Net Core as a frontend client. However, I'm facing some challenges when trying to use a Blazor Server client frontend instead. I've tried applying the same technique I use with an Asp.Net Core frontend, but it just doesn't seem to work.

Here's the code I'm using in the
Program.cs
of the Asp.Net Core client:

JwtSecurityTokenHandler.DefaultMapInboundClaims = false;

builder.Services.AddAuthentication(options =>
{
    options.DefaultScheme = "Cookies";
    options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
    options.Authority = "https://localhost:5001";
    options.ClientId = "web";
    options.ClientSecret = "secret";
    options.ResponseType = "code";

    options.Scope.Clear();
    options.Scope.Add("verification");
    options.ClaimActions.MapJsonKey("email_verified", "email_verified");
    options.Scope.Add("openid");
    options.Scope.Add("profile");
    options.GetClaimsFromUserInfoEndpoint = true;
    options.SaveTokens = true;
});

Followed by:
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();

app.MapRazorPages().RequireAuthorization();


When I run the server and then the client, it successfully redirects to the server (at localhost:5001) while waiting for authorization. However, when attempting the same setup with a Blazor Server as a client, it doesn't work. Does anyone have any insights into why this might be happening, and any suggestions on how to make it work?

I'd greatly appreciate any help or advice on this matter. 🙏
Was this page helpful?