Identityserver JWKS endpoint generates Nullreference

Viewed 36

When accessing https://example.com/.well-known/openid-configuration/jwks in order to debug my Identityserver issues (The key {xxxxxxxxxxxxxxxxxxxxx} was not found in the key ring), the JWKS endpoint fails and returns the following;

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Object.GetType()
   at Duende.IdentityServer.ResponseHandling.DiscoveryResponseGenerator.CreateJwkDocumentAsync() in /_/src/IdentityServer/ResponseHandling/Default/DiscoveryResponseGenerator.cs:line 440
   at Duende.IdentityServer.Endpoints.DiscoveryKeyEndpoint.ProcessAsync(HttpContext context) in /_/src/IdentityServer/Endpoints/DiscoveryKeyEndpoint.cs:line 54
   at Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events, IIssuerNameService issuerNameService, IBackChannelLogoutService backChannelLogoutService) in /_/src/IdentityServer/Hosting/IdentityServerMiddleware.cs:line 103
   at Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events, IIssuerNameService issuerNameService, IBackChannelLogoutService backChannelLogoutService) in /_/src/IdentityServer/Hosting/IdentityServerMiddleware.cs:line 103
   at Duende.IdentityServer.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes) in /_/src/IdentityServer/Hosting/MutualTlsEndpointMiddleware.cs:line 95
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Duende.IdentityServer.Hosting.DynamicProviders.DynamicSchemeAuthenticationMiddleware.Invoke(HttpContext context) in /_/src/IdentityServer/Hosting/DynamicProviders/DynamicSchemes/DynamicSchemeAuthenticationMiddleware.cs:line 48
   at Duende.IdentityServer.Hosting.BaseUrlMiddleware.Invoke(HttpContext context) in /_/src/IdentityServer/Hosting/BaseUrlMiddleware.cs:line 32
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Any thoughts on what this could be?

1 Answers

You should see a key in the JWKS endpoint when you use AddDeveloperSigningCredential(). If not, then you have some other issues.

As I mentioned earlier, there is also a built-in Key management system in IdentityServer, and it creates its keys in the \Keys folder, as the image below shows:

enter image description here

If you don't use the key manager, then you should disable it using:

var builder = services.AddIdentityServer(options =>
{
    options.KeyManagement.Enabled = false;
    ...
});
Related