gpt4 book ai didi

c# - 在 Linux 应用服务上为 IdentityServer4 提供 key

转载 作者:行者123 更新时间:2023-12-02 07:03:27 26 4
gpt4 key购买 nike

我正在尝试在 Linux 应用服务 (B1) 上运行的 netcore 3.1 应用上配置 IdentityServer4。我试图从文件系统加载 key 并在配置时将其传递给 IdentityServer ( as per here ),但我提供的 key 似乎被丢弃,因为 IdentityServer 尝试查找配置来查找 key 本身 ( line 70 appears to be where the exception is thrown from )。

    public void ConfigureServices(IServiceCollection services)
{
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();

services.AddIdentityServer()
.AddSigningCredential(GetCert())
.AddApiAuthorization<IdentityUser, ApplicationDbContext>();

services.AddAuthentication()
.AddIdentityServerJwt();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseAuthentication();
app.UseIdentityServer(); // exception thrown here
app.UseAuthorization();
}


private X509Certificate2 GetCert()
{
// Linux App Service puts keys configured in the App Service in this directory
// I have checked - the key is correctly placed here
var bytes = System.IO.File.ReadAllBytes("/var/ssl/private/XYZTHUMBPRINTXYZ.p12");
return new X509Certificate2(bytes);
}

我应该注意,这实际上并不是将 key 获取到 Azure 或应用程序本身的问题,我已经在文件系统上验证了它,并且应用程序可以从中创建有效的 key ,这似乎是被 IdentityServer 丢弃。

由于 Windows 类型的 KeyStore 在 Linux 服务上不可用,因此 appsettings 配置(下面的示例)不起作用。

  "IdentityServer": {
"Key": {
"Type": "Store",
"StoreName": "My",
"StoreLocation": "CurrentUser",
"Name": "CN=example.com"
}
},

最佳答案

在这个问题的答案的帮助下,我已经弄清楚了它的真相 - Adding Identityserver authentication to net core 3 app fails with 'Key type not specified.'

问题是 AddApiAuthorization<IdentityUser, ApplicationDbContext>()内部调用AddSigningCredentials()这将指示 IdentityServer 查看应用程序配置以找出要使用的 key 。无论 AddSigningCredential(cert) 都会执行此操作在之前或之后调用。

为了解决我的问题,我内联了 AddApiAuthorization<IdentityUser, ApplicationDbContext>()方法并删除了从配置中查找更多 key 的行,该应用程序现在可以在 Linux 应用程序服务上运行。

我还在 IdentityServer 的 github 上提出了这个问题,留下链接以防项目所有者对该决议发表评论 - https://github.com/IdentityServer/IdentityServer4/issues/4000

关于c# - 在 Linux 应用服务上为 IdentityServer4 提供 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59849734/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com