Tany3450
Tany3450

Reputation: 338

.Net-Core IdentityServer - Type not supported

I am trying to deploy my .net core 3.1 project to debian using nginx runtime-dependent. I developed it on Windows, everything works fine while debugging. However, on production I am stuck with a 502 because of this error;

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()

I tried to add signing credential to identityServer like this;

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

Also I added a key to IdentityServer in appsettings.json;

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

But it didn't work. This seems to be a problem related to GetClients() method rather than the certificate. I also tried configuring clients through code. Any other idea? Thank you!

Upvotes: 1

Views: 1569

Answers (1)

nahidf
nahidf

Reputation: 2394

This issue is cause of the way you configured list of clients on appsettings.json. The profile property for client should be one of items listed on https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity-api-authorization?view=aspnetcore-3.1#application-profiles

Here is where error is raised https://github.com/dotnet/aspnetcore/blob/master/src/Identity/ApiAuthorization.IdentityServer/src/Configuration/ConfigureClients.cs#L48

Upvotes: 2

Related Questions