© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
4 replies
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
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;
});
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();
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. 🙏
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

duende identity server
C#CC# / help
3y ago
Protecting an API with Duende Server
C#CC# / help
3y ago
API protection with JWT + Duende server
C#CC# / help
3y ago
blazor authentication service (WEB Api server)
C#CC# / help
11mo ago