InvalidOperationException: Key type not specified. Microsoft.AspNetCore.ApiAuthorization.IdentityServer.ConfigureSigningCredentials.LoadKey()
As you already answered - The solution is to add the following settings into appsettings.json, within the "IdentityServer" brackets. This followed the "Clients" element:
For File
"IdentityServer": { "Key": { "Type": "File", "FilePath": "C:\cert.pfx", "Password": "password123" } }
For Development (don't use in production obviously)
"IdentityServer": { "Key": { "Type": "Development" } }
For Store
"IdentityServer": { "Key": { "Type": "Store", "StoreName": "My", "StoreLocation": "CurrentUser", "Name": "CN=MyApplication" }}
The solution is to add the following settings into appsettings.json, within the "IdentityServer" brackets. This followed the "Clients" element:
"IdentityServer": { "Key": { "Type": "Store", "StoreName": "My", "StoreLocation": "CurrentUser", "Name": "CN=**WHATEVER NAME YOU USED AS THE DISTINGUISHED SUBJECT FOR YOUR CERT**" }
This follows the instructions here. Note, that this was accomplished with a self-signed certificate created with OpenSSL following this post.
From the above mentioned code , i am assuming that below line of coding is causing nullargument exception.
.AddSigningCredential(cert);
because the **cert**
is null,which comes down to your method GetMyX509Certificate
try { System.Diagnostics.Trace.TraceInformation($"HELLO! TRYING TO GET THE CERTIFICATE"); return new X509Certificate2(File.ReadAllBytes(pfxFilePath), password, sFlags); } catch (PlatformNotSupportedException ex) { System.Diagnostics.Trace.TraceError($"HELLO! {ex.Message}"); if(sFlags.HasFlag(X509KeyStorageFlags.EphemeralKeySet)) { return GetMyX509Certificate(pfxFilePath,password,X509KeyStorageFlags.MachineKeySet); } else { return null; } } catch (Exception ex) { System.Diagnostics.Trace.TraceError($"HELLO! {ex.Message}"); return null; }
Since you code is not throwing **PlatformNotSupportedException**
type of exception, for sure it will throwing Generic Exception which will be later catched by your last line
catch (Exception ex) { System.Diagnostics.Trace.TraceError($"HELLO! {ex.Message}"); return null; }
and from here you are returning null which internally giving you the actual error.
I don't understand why are you not able to use KUDU, but if i were you , i would suggest you to enable information logging using some logging library , e.g. File system logging or Application insighy using custom telemetry.
Hope it helps.