Dejan Stojanović
Dejan Stojanović

Reputation: 119

Basic auth for healthchecks in asp.net core

I have an ASP.NET Core 3.1 API which already uses OAuth for authorization. I added healthchecks middleware and I would like to make it protected with basic auth so that client which check the health status can simply provide credentials to check the service health. So far I did not manage to configure it for the healthcheck endpoint. Any clue how this can be added?

Upvotes: 2

Views: 1989

Answers (1)

Bao To Quoc
Bao To Quoc

Reputation: 382

You can use RequireAuthorization method. For example:

app.UseEndpoints(endpoints =>
{
    endpoints.MapHealthChecks("/health").RequireAuthorization();
});

Upvotes: -1

Related Questions