如何使用 .NET 8 在 Blazor Server 项目中同时进行基于 JWT 令牌和基于 cookie 的身份验证?

问题描述 投票:0回答:1

我有一个通过

Blazor Server app
进行身份验证的
ASP.NET Identity cookies
项目,并且我使用
APIs
方法向其中添加了几个
minimal API
。这些 API 旨在通过
mobile application
进行调用,并且 API 需要通过
JWT tokens
进行身份验证。我应该做什么才能实现这个目标?

当前身份验证配置:

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();
c# asp.net-web-api blazor blazor-server-side .net-8.0
1个回答
0
投票

观看此视频,其中使用了以下两者: https://m.youtube.com/watch?v=w5w00b6V6fw

© www.soinside.com 2019 - 2024. All rights reserved.