namespace IdentityShroud.Api.Apis.ISResults; public class ISUnauthorizedHttpResult : IResult, IStatusCodeHttpResult { private readonly List _wwwAuthenticateValues; /// /// Initializes a new instance of the class. /// internal ISUnauthorizedHttpResult(List wwwAuthenticateValues) { _wwwAuthenticateValues = wwwAuthenticateValues; } /// /// Gets the HTTP status code: /// public int StatusCode => StatusCodes.Status401Unauthorized; int? IStatusCodeHttpResult.StatusCode => StatusCode; /// public Task ExecuteAsync(HttpContext httpContext) { ArgumentNullException.ThrowIfNull(httpContext); // Creating the logger with a string to preserve the category after the refactoring. // var loggerFactory = httpContext.RequestServices.GetRequiredService(); // var logger = loggerFactory.CreateLogger("IdentityShroud.Api.Results.ISUnauthorizedResult"); // HttpResultsHelper.Log.WritingResultAsStatusCode(logger, StatusCode); httpContext.Response.Headers.WWWAuthenticate = new(_wwwAuthenticateValues.ToArray()); httpContext.Response.StatusCode = StatusCode; return Task.CompletedTask; } }