Duende.IdentityServer.Admin icon indicating copy to clipboard operation
Duende.IdentityServer.Admin copied to clipboard

Identioty server health check method call has wrong parameters

Open farshid3003 opened this issue 4 months ago • 2 comments

Describe the bug

Admin and API health checks are unhealthy as this method call is wrong. you have the following health check code:

            var healthChecksBuilder = services.AddHealthChecks()
                .AddDbContextCheck<TConfigurationDbContext>("ConfigurationDbContext")
                .AddDbContextCheck<TPersistedGrantDbContext>("PersistedGrantsDbContext")
                .AddDbContextCheck<TIdentityDbContext>("IdentityDbContext")
                .AddDbContextCheck<TLogDbContext>("LogDbContext")
                .AddDbContextCheck<TAuditLoggingDbContext>("AuditLogDbContext")
                .AddDbContextCheck<TDataProtectionDbContext>("DataProtectionDbContext")
                .AddIdentityServer(new Uri(identityServerUri), "Identity Server"); 

AddIdentityServer method parameters passed in the wrong order. This is the Microsoft method implementation:

public static IHealthChecksBuilder AddIdentityServer(this IHealthChecksBuilder builder, Uri idSvrUri, string discoverConfigurationSegment = ".well-known/openid-configuration", string? name = null, HealthStatus? failureStatus = null, IEnumerable<string>? tags = null, TimeSpan? timeout = null) 

The best way is change the code to:

            var healthChecksBuilder = services.AddHealthChecks()
                .AddDbContextCheck<TConfigurationDbContext>("ConfigurationDbContext")
                .AddDbContextCheck<TPersistedGrantDbContext>("PersistedGrantsDbContext")
                .AddDbContextCheck<TIdentityDbContext>("IdentityDbContext")
                .AddDbContextCheck<TLogDbContext>("LogDbContext")
                .AddDbContextCheck<TAuditLoggingDbContext>("AuditLogDbContext")
                .AddDbContextCheck<TDataProtectionDbContext>("DataProtectionDbContext")
               .AddIdentityServer(idSvrUri: new Uri(identityServerUri), name: "Identity Server");

This code needs to be changed for the admin and API project.

To Reproduce

Steps to reproduce the behavior:

Relevant parts of the log file

2024-02-25 21:51:53.430 +00:00 [ERR] Health check idsvr with status "Unhealthy" completed after 271.306ms with message 'Discover endpoint is not responding with 200 OK, the current status is NotFound and the content '
2024-02-25 21:52:40.264 +00:00 [ERR] Health check idsvr with status "Unhealthy" completed after 247.469ms with message 'Discover endpoint is not responding with 200 OK, the current status is NotFound and the content '
2024-02-25 22:04:41.702 +00:00 [ERR] Health check idsvr with status "Unhealthy" completed after 179.9718ms with message 'Discover endpoint is not responding with 200 OK, the current status is NotFound and the content '

farshid3003 avatar Feb 25 '24 23:02 farshid3003