Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4137

How can I simultaneously have JWT token-based and cookie-based authentication in a Blazor Server project using .NET 8?

$
0
0

I have a Blazor Server app project authenticated via ASP.NET Identity cookies, and I've added several APIs to it using the minimal API approach. These APIs are intended to be called through a mobile application, and it's necessary for the APIs to be authenticated via JWT tokens. What should I do to achieve this?

Current authentication Config:

builder.Services.AddCascadingAuthenticationState();builder.Services.AddScoped<IdentityUserAccessor>();builder.Services.AddScoped<IdentityRedirectManager>();builder.Services.AddScoped<AuthenticationStateProvider,     IdentityRevalidatingAuthenticationStateProvider>();builder.Services.AddAuthentication(options =>{    options.DefaultScheme = IdentityConstants.ApplicationScheme;    options.DefaultSignInScheme = IdentityConstants.ApplicationScheme;}).AddIdentityCookies();builder.Services.AddIdentityCore<User>(options => options.SignIn.RequireConfirmedAccount = false).AddRoles<Role>().AddEntityFrameworkStores<Infrastructure.Persistence.ApplicationDbContext>().AddSignInManager().AddDefaultTokenProviders();

Viewing all articles
Browse latest Browse all 4137

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>