c# – 在负载均衡器后面运行的Identity Server 4
发布时间:2020-12-15 21:06:21 所属栏目:百科 来源:网络整理
导读:我使用Entity Framework为我的项目设置了Identity Server 4.我已将服务配置为使用持久授权存储和签名证书. services.AddIdentityServer() .AddSigningCredential(Config.GetSigningCertificate()) .AddResourceOwnerValidatorResourceOwnerPasswordValidator
我使用Entity Framework为我的项目设置了Identity Server 4.我已将服务配置为使用持久授权存储和签名证书.
services.AddIdentityServer() .AddSigningCredential(Config.GetSigningCertificate()) .AddResourceOwnerValidator<ResourceOwnerPasswordValidator>() .AddProfileService<ProfileService>() .AddConfigurationStore(builder => builder.UseSqlServer(connectionString,options => options.MigrationsAssembly(migrationsAssembly))) .AddOperationalStore(builder => builder.UseSqlServer(connectionString,options => options.MigrationsAssembly(migrationsAssembly))); 这是服务的配置. 问题是当我在负载均衡器后面运行我的服务器时,例如处理所有请求的2个identic实例,用户未登录的服务器无法解码JWT令牌,导致401未经授权的错误. 我假设令牌的签名方法或他们的征名是问题,但我找不到解决这个问题的方法. 这是我配置的其余部分. 配置: app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions { Authority = url,// Authority = "http://localhost:5000",AllowedScopes = { "WebAPI" },RequireHttpsMetadata = false,AutomaticAuthenticate = true,AutomaticChallenge = true,}); 客户端: new Client { ClientId = "Angular2SPA",AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,// Resource Owner Password Credential grant. AllowAccessTokensViaBrowser = true,RequireClientSecret = false,// This client does not need a secret to request tokens from the token endpoint. AccessTokenLifetime = 7200,// Lifetime of access token in seconds. AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId,// For UserInfo endpoint. IdentityServerConstants.StandardScopes.Profile,"roles","WebAPI" },AllowOfflineAccess = true,// For refresh token. AccessTokenType = AccessTokenType.Jwt } 我还实现了自己的IResourceOwnerPasswordValidator和IProfileService. 知道为什么会这样吗? 解决方法
我有一个类似的问题,负载平衡Identity Server 4,并能够使用Startup.cs的ConfigureServices中的.AddDataProtection()共享密钥.
public void ConfigureServices(IServiceCollection services) { // Other service configurations services.AddDataProtection(); // Additional service configurations } 作为旁注,如果你走这条路线,考虑使用像这样的扩展来加密这些密钥(在你决定使用的任何媒体中) HTH (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |