[英]Identity Server with MVC Client running behind an AWS Load Balancer
[英]Identity Server 4 Running Behind a load Balancer
我使用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
}
作為旁注,如果你走這條路線,考慮使用像.ProtectKeysWith*
這樣的擴展加密這些鍵(在你決定使用的任何媒體中)(有幾個選項)。 有關詳細信息,請參閱https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/introduction?view=aspnetcore-2.1
HTH
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.