2023年7月18日发(作者:)
ABP之IdentityServer4集成源码模块:tyServer
初始化IdentityServer4在ABP的分离部署模式中,有⼀个类库专门处理IdentityServer4,作为认证授权服务器。⾸先将IdentityServer设为启动项⽬,修改⾥⾯的ConnectionStrings节点,然后再Nuget管理器控制台中运⾏Update-Database,完成数据迁移。有⼀个数据种⼦⽣成器类 IdentityServerDataSeedContributor 专门处理初始化IdentityServer。
1. 依赖默认的IdentityServer4主要依赖于 tyServer 这个Nuget包来⽀持基于IdentityServer4的登录和登出。从源码可以看到,这个包⼜依赖于AbpAccountWebModule、AbpIdentityServerDomainModule。前者处理登录界⾯,后者处理IdentityServer4(其实就是基于原⽣的IdentityServer4做了⼀层集成处理)。IdentityServerSupportedLoginModel、IdentityServerSupportedLogoutModel是仅有的两个类⽤于处理登录登出的,这⾥⾯涉及到⼤量的IdentityServer4的相关处理,可以好好看看。
初始化 Api服务器以及Web界⾯服务器这两个东西就是.项⽬以及.项⽬,主要就是修改⾥⾯的ConnectionStrings节点就可以了。在这⾥要特别说下需要部署redis,应该api项⽬依赖于它。⽽在Web项⽬中,需要配置OpenId Connect⾝份认证private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration) { hentication(options => { tScheme = "Cookies"; tChallengeScheme = "oidc"; }) .AddCookie("Cookies", options => { TimeSpan = ys(365); }) .AddOpenIdConnect("oidc", options => { ity = configuration["AuthServer:Authority"]; eHttpsMetadata = false; seType = Token; Id = configuration["AuthServer:ClientId"]; Secret = configuration["AuthServer:ClientSecret"]; kens = true; imsFromUserInfoEndpoint = true; ("role"); ("email"); ("phone"); ("ABPModuleSample_WithUI"); nKey(me, "name"); Claim("name"); }); }虽然也有⼀个控制器,但是这个控制器并没有使⽤,主要还是web应⽤程序,即Pages⽬录下的页⾯来处理,调⽤ChallengeAsync⽅法,直接重定向到指定AuthenticationScheme 的中间件。
总结. 项⽬使⽤OpenId Connect⾝份认证从.IdentityServer获取当前⽤户的⾝份和访问令牌. 然后使⽤访问令牌调⽤ . API 服务器使⽤bearer token验证访问令牌获取当前⽤户声明并授权⽤户.
参考:
发布者:admin,转转请注明出处:http://www.yc00.com/web/1689648472a273646.html
评论列表(0条)