BasicAuth bezieht Realm aus dem Validator. DNS Resolve für E-Mail Validierung geändert. Moq-Package hinzugefügt.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user