Updating to new options pattern
This commit is contained in:
parent
deca0f3bef
commit
11025b894e
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Authentication;
|
||||
using Microsoft.AspNet.Http.Features.Authentication;
|
||||
|
|
|
|||
|
|
@ -5,11 +5,12 @@ using System;
|
|||
using System.Globalization;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.AspNet.Http.Features.Authentication;
|
||||
using Microsoft.AspNet.Http.Features.Authentication.Internal;
|
||||
using Microsoft.Extensions.Internal;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
|
||||
namespace Microsoft.AspNet.IISPlatformHandler
|
||||
|
|
@ -21,7 +22,7 @@ namespace Microsoft.AspNet.IISPlatformHandler
|
|||
private readonly RequestDelegate _next;
|
||||
private readonly IISPlatformHandlerOptions _options;
|
||||
|
||||
public IISPlatformHandlerMiddleware(RequestDelegate next, IISPlatformHandlerOptions options)
|
||||
public IISPlatformHandlerMiddleware(RequestDelegate next, IOptions<IISPlatformHandlerOptions> options)
|
||||
{
|
||||
if (next == null)
|
||||
{
|
||||
|
|
@ -31,8 +32,9 @@ namespace Microsoft.AspNet.IISPlatformHandler
|
|||
{
|
||||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
_next = next;
|
||||
_options = options;
|
||||
_options = options.Value;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext httpContext)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.AspNet.IISPlatformHandler;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
|
|
@ -21,31 +22,7 @@ namespace Microsoft.AspNet.Builder
|
|||
throw new ArgumentNullException(nameof(app));
|
||||
}
|
||||
|
||||
return app.UseIISPlatformHandler(options => { });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds middleware for interacting with the IIS HttpPlatformHandler reverse proxy module.
|
||||
/// This will handle forwarded Windows Authentication, request scheme, remote IPs, etc..
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="configureOptions"></param>
|
||||
/// <returns></returns>
|
||||
public static IApplicationBuilder UseIISPlatformHandler(this IApplicationBuilder app, Action<IISPlatformHandlerOptions> configureOptions)
|
||||
{
|
||||
if (app == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(app));
|
||||
}
|
||||
if (configureOptions == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(configureOptions));
|
||||
}
|
||||
|
||||
var options = new IISPlatformHandlerOptions();
|
||||
configureOptions(options);
|
||||
|
||||
return app.UseMiddleware<IISPlatformHandlerMiddleware>(options);
|
||||
return app.UseMiddleware<IISPlatformHandlerMiddleware>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -66,7 +43,7 @@ namespace Microsoft.AspNet.Builder
|
|||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
return app.UseMiddleware<IISPlatformHandlerMiddleware>(options);
|
||||
return app.UseMiddleware<IISPlatformHandlerMiddleware>(Options.Create(options));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http.Authentication;
|
||||
using Microsoft.AspNet.IISPlatformHandler;
|
||||
|
||||
namespace Microsoft.AspNet.IISPlatformHandler
|
||||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
public class IISPlatformHandlerOptions
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@
|
|||
"Microsoft.Extensions.SecurityHelper.Sources": {
|
||||
"type": "build",
|
||||
"version": "1.0.0-*"
|
||||
}
|
||||
},
|
||||
"Microsoft.Extensions.Options": "1.0.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"net451": { },
|
||||
|
|
|
|||
|
|
@ -47,7 +47,10 @@ namespace Microsoft.AspNet.IISPlatformHandler
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseIISPlatformHandler(options => options.FlowWindowsAuthentication = false);
|
||||
app.UseIISPlatformHandler(new IISPlatformHandlerOptions
|
||||
{
|
||||
FlowWindowsAuthentication = false
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var auth = (IHttpAuthenticationFeature)context.Features[typeof(IHttpAuthenticationFeature)];
|
||||
|
|
|
|||
Loading…
Reference in New Issue