skoruba / Duende.IdentityServer.Admin

The administration for the Duende IdentityServer and Asp.Net Core Identity ⚡
Apache License 2.0
542 stars 188 forks source link

Identioty server health check method call has wrong parameters #200

Open farshid3003 opened 4 months ago

farshid3003 commented 4 months ago

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 '
skoruba commented 4 months ago

Thanks! I will fix it.

jochance commented 4 months ago

This also exists in the same location in the Admin.Api.