38 lines
No EOL
1.4 KiB
C#
38 lines
No EOL
1.4 KiB
C#
namespace IdentityShroud.Api.Apis.ISResults;
|
|
|
|
public class ISUnauthorizedHttpResult : IResult, IStatusCodeHttpResult
|
|
{
|
|
private readonly List<string> _wwwAuthenticateValues;
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="UnauthorizedHttpResult"/> class.
|
|
/// </summary>
|
|
internal ISUnauthorizedHttpResult(List<string> wwwAuthenticateValues)
|
|
{
|
|
_wwwAuthenticateValues = wwwAuthenticateValues;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the HTTP status code: <see cref="StatusCodes.Status401Unauthorized"/>
|
|
/// </summary>
|
|
public int StatusCode => StatusCodes.Status401Unauthorized;
|
|
|
|
int? IStatusCodeHttpResult.StatusCode => StatusCode;
|
|
|
|
/// <inheritdoc />
|
|
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<ILoggerFactory>();
|
|
// 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;
|
|
}
|
|
} |