新文章 网摘 文章 随笔 日记

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

posted @ 2020-03-31 14:22  岭南春  阅读(97)  评论(0)    收藏  举报