杭州网企业网站建设,安远网站建设,自学做网站可以嘛,做网站用什么技术好一.前言我们在实际使用 IdentityServer4 的时候#xff0c;可能会在使用 IdentityServer4 项目添加一些API#xff0c;比如 找回密码、用户注册、修改用户资料等#xff0c;这些API与IdentityServer4怎么共存在一个项目呢#xff1f;二.整合1.首先在 Startup.cs 中添加 Ide… 一.前言我们在实际使用 IdentityServer4 的时候可能会在使用 IdentityServer4 项目添加一些API比如 找回密码、用户注册、修改用户资料等这些API与IdentityServer4怎么共存在一个项目呢二.整合1.首先在 Startup.cs 中添加 IdentityServer4services.AddIdentityServer(optionsoptions.Authentication.CookieAuthenticationScheme Cookies).AddDeveloperSigningCredential().AddInMemoryIdentityResources(Config.GetIdentityResources()).AddInMemoryApiResources(Config.GetApis()).AddInMemoryClients(Config.GetClients()).AddTestUsers(Config.GetUsers());2.然后在添加 IdentityServer4 下添加认证services.AddAuthentication(Bearer).AddCookie(Cookies).AddJwtBearer(Bearer, options { //identityserver4 地址 也就是本项目地址options.Authority http://localhost:5000;options.RequireHttpsMetadata false;options.Audience api1;});注意事项Cookie Scheme 是非必须的但是如果不设置会报错但是也不会影响正常使用AddAuthentication 必须必须必须 放在 AddIdentityServer 之后3.中间件配置app.UseIdentityServer();这里只需 UseIdentityServer 即可三.测试在 IdentityServer4 项目添加一个 Controller[Route(identity)]
[Authorize]public class IdentityController : ControllerBase{ public IActionResult Get() { return new JsonResult(from c in User.Claims select new { c.Type, c.Value });}
}将 IdentityServer4 项目的端口设置为5000使用密码模式下面进行测试1.请求Token2.请求API四.资料本文Demo:https://github.com/stulzq/IdentityServer4.Samples/tree/master/Practice/05_Integration原文地址https://www.cnblogs.com/stulzq/p/10346095.html.NET社区新闻深度好文欢迎访问公众号文章汇总 http://www.csharpkit.com