1
0

BasicAuth bezieht Realm aus dem Validator. DNS Resolve für E-Mail Validierung geändert. Moq-Package hinzugefügt.

This commit is contained in:
2022-01-30 14:25:13 +01:00
parent a885f15ebb
commit 80e5382553
11 changed files with 247 additions and 19 deletions

View File

@@ -12,19 +12,16 @@ namespace AMWD.Common.AspNetCore.BasicAuthentication
public class BasicAuthenticationMiddleware
{
private readonly RequestDelegate next;
private readonly string realm;
private readonly IBasicAuthenticationValidator validator;
/// <summary>
/// Initializes a new instance of the <see cref="BasicAuthenticationMiddleware"/> class.
/// </summary>
/// <param name="next">The following delegate in the process chain.</param>
/// <param name="realm">The realm to display when requesting for credentials.</param>
/// <param name="validator">A basic authentication validator.</param>
public BasicAuthenticationMiddleware(RequestDelegate next, string realm, IBasicAuthenticationValidator validator)
public BasicAuthenticationMiddleware(RequestDelegate next, IBasicAuthenticationValidator validator)
{
this.next = next;
this.realm = realm;
this.validator = validator;
}
@@ -53,10 +50,8 @@ namespace AMWD.Common.AspNetCore.BasicAuthentication
}
httpContext.Response.Headers["WWW-Authenticate"] = "Basic";
if (!string.IsNullOrWhiteSpace(realm))
{
httpContext.Response.Headers["WWW-Authenticate"] += $" realm=\"{realm}\"";
}
if (!string.IsNullOrWhiteSpace(validator.Realm))
httpContext.Response.Headers["WWW-Authenticate"] += $" realm=\"{validator.Realm}\"";
httpContext.Response.StatusCode = StatusCodes.Status401Unauthorized;
}

View File

@@ -9,6 +9,11 @@ namespace AMWD.Common.AspNetCore.BasicAuthentication
/// </summary>
public interface IBasicAuthenticationValidator
{
/// <summary>
/// Gets or sets the realm to use when requesting authentication.
/// </summary>
string Realm { get; set; }
/// <summary>
/// Validates a username and password for Basic Authentication.
/// </summary>