【问题标题】:.Net-Core IdentityServer - Type not supported.Net-Core IdentityServer - 不支持类型
【发布时间】:2020-07-14 08:29:30
【问题描述】:

我正在尝试使用 nginx 运行时相关将我的 .net core 3.1 项目部署到 debian。我在 Windows 上开发它,调试时一切正常。但是,由于这个错误,在生产中我遇到了 502;

System.InvalidOperationException: Type '' is not supported.
  at Microsoft.AspNetCore.ApiAuthorization.IdentityServer.ConfigureClients.GetClients()+MoveNext()
  at Microsoft.AspNetCore.ApiAuthorization.IdentityServer.ConfigureClients.Configure(ApiAuthorizationOptions options)
  at Microsoft.Extensions.Options.OptionsFactory`1.Create(String name)
  at Microsoft.Extensions.Options.OptionsManager`1.<>c__DisplayClass5_0.<Get>b__0()
  at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
  at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
  at System.Lazy`1.CreateValue()
  at System.Lazy`1.get_Value()
  at Microsoft.Extensions.Options.OptionsCache`1.GetOrAdd(String name, Func`1 createOptions)
  at Microsoft.Extensions.Options.OptionsManager`1.Get(String name)
  at Microsoft.Extensions.Options.OptionsManager`1.get_Value()

我尝试像这样向 identityServer 添加签名凭据;

var bytes = File.ReadAllBytes("/etc/myapp/IdentityServerCertificate.pfx");
var cert = new X509Certificate2(bytes, "PWD");
identityServer.AddSigningCredential(cert);

我还在 appsettings.json 中添加了 IdentityServer 的密钥;

      "IdentityServer": {
        "Clients": {
            "MyClient": {
                "Profile": "IdentityServerSPA"
            },
            "Key": {
                "Type": "File",
                 "FilePath": "/etc/myapp/IdentityServerCertificate.pfx",
                "Password": "PWD"
                }
        },

但它没有用。这似乎是与 GetClients() 方法而不是证书相关的问题。我还尝试通过代码配置客户端。还有什么想法吗?谢谢!

【问题讨论】:

  • 你能显示GetClients方法的内容吗?那里似乎有什么问题。
  • 请查看@nahidf 分享下方的github链接。

标签: asp.net-core nginx .net-core debian identityserver4


【解决方案1】:

【讨论】:

  • 是的,但我仍然不知道为什么。我已经更新了上面的 appsettings.json 以包含客户详细信息。它看起来很简单,但不起作用。我也试过通过代码配置客户端。
  • @Tany3450 你用什么配置发布到产品?例如,如果您使用prod 配置发布您需要有appsettings.Prod.json。在此处查看详细信息docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/…docs.microsoft.com/en-us/aspnet/core/fundamentals/…
  • 它读取 appsettings.json 所以我认为它很好。我使用这个命令; dotnet publish --configuration Release -r linux-x64 --self-contained false
  • @Tany3450 我的问题更多是关于在部署后是否复制和读​​取正确的 appsettings,因为如果事情在本地工作但不能在 prod 上工作意味着在部署期间某事已关闭,请查看此答案以确保您正确部署设置stackoverflow.com/a/54216774/3486567
  • 谢谢,确实是因为key是在Clients而不是IdentityServer下定义的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-08
  • 2020-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多