我有一些问题,比如this,但我无法理解如何为Debian解决这个问题。
首先,我按照以下说明配置我的应用程序
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme =MyAuthSchemeName,
CookieName = MyCookiName,
AutomaticAuthenticate = true,
AutomaticChallenge = false,
SlidingExpiration = true,
ExpireTimeSpan = TimeSpan.FromDays(1),
DataProtectionProvider = DataProtectionProvider.Create(MyApplicationName)
});
app.UseJwtBearerAuthentication(new JwtBearerOptions
{
AutomaticChallenge = false,
AutomaticAuthenticate = true,
Authority = IdentityServerConnectionString,
RequireHttpsMetadata = false,
BackchannelHttpHandler = new HttpClientHandler().ServerCertificateCustomValidationCallback = (request, cert, chain, errors) => true,
TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = false,
ValidateIssuer = false,
}
});
app.UseMvc();
对于Windows,它完美运行(我使用Host启动此代码,而不是IIS!),但对于Debian,它失败了。 有什么想法吗?
UPD:我在日志中看到下一条消息:Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware MyAuthSchemeName未经过身份验证。失败消息:取消保护票证失败
答案 0 :(得分:2)
我找到了解决这个问题的方法。 关键原因是DataProtectionProvider的设置。 对于Debian,它需要使用下面的代码
Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddDataProtection().SetApplicationName(ApplicationName).
PersistKeysToFileSystem(
new DirectoryInfo(Configuration["/some_path_to_folder_for_keys"]))
}
应该删除cookie的dataprovider初始化(来自UseCookieAuthentication());