MVC客户端和Api共同使用IdentityServer4进行工作
我需要的是让一个MVC客户端和一个Api在同一个项目上一起工作,并且都受到身份项目安全性的保护。这可能吗?。
制作一个工作样本。
技巧是为JwtBearer添加身份验证处理程序,并在API控制器中使用相同的方案。
Startup.cs:
services.AddAuthentication() .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options => { options.Authority = "http://localhost:5000"; options.RequireHttpsMetadata = false; options.Audience = "api1"; options.SaveToken = true; });
API控制器:
[Route("[controller]")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public class IdentityController : ControllerBase { }
https://github.com/IdentityServer/IdentityServer4/issues/2698
浙公网安备 33010602011771号