From 5753784ac4321385636c63afb9ff4dc127c10e3a Mon Sep 17 00:00:00 2001 From: Chris R Date: Thu, 13 Jul 2017 11:22:38 -0700 Subject: [PATCH] #391 Add back the DisplayName setting --- samples/IISSample/Startup.cs | 7 ++++++- .../IISMiddleware.cs | 2 +- .../IISOptions.cs | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/samples/IISSample/Startup.cs b/samples/IISSample/Startup.cs index b496b8a5cb..4174c4b45f 100644 --- a/samples/IISSample/Startup.cs +++ b/samples/IISSample/Startup.cs @@ -1,8 +1,10 @@ using System; using System.Linq; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Server.IISIntegration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -15,13 +17,14 @@ namespace IISSample // These two middleware are registered via an IStartupFilter in UseIISIntegration but you can configure them here. services.Configure(options => { + options.AuthenticationDisplayName = "Windows Auth"; }); services.Configure(options => { }); } - public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory) + public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory, IAuthenticationSchemeProvider authSchemeProvider) { var logger = loggerfactory.CreateLogger("Requests"); @@ -50,6 +53,8 @@ namespace IISSample await context.Response.WriteAsync(Environment.NewLine); await context.Response.WriteAsync("User: " + context.User.Identity.Name + Environment.NewLine); + var scheme = await authSchemeProvider.GetSchemeAsync(IISDefaults.AuthenticationScheme); + await context.Response.WriteAsync("DisplayName: " + scheme?.DisplayName + Environment.NewLine); await context.Response.WriteAsync(Environment.NewLine); await context.Response.WriteAsync("Headers:" + Environment.NewLine); diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/IISMiddleware.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/IISMiddleware.cs index 506a4894c7..e536519707 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration/IISMiddleware.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/IISMiddleware.cs @@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration if (_options.ForwardWindowsAuthentication) { - authentication.AddScheme(new AuthenticationScheme(IISDefaults.AuthenticationScheme, displayName: null, handlerType: typeof(AuthenticationHandler))); + authentication.AddScheme(new AuthenticationScheme(IISDefaults.AuthenticationScheme, _options.AuthenticationDisplayName, typeof(AuthenticationHandler))); } _pairingToken = pairingToken; diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/IISOptions.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/IISOptions.cs index d175236e0b..efd9eec1f3 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration/IISOptions.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/IISOptions.cs @@ -12,6 +12,11 @@ namespace Microsoft.AspNetCore.Builder /// public bool AutomaticAuthentication { get; set; } = true; + /// + /// Sets the display name shown to users on login pages. The default is null. + /// + public string AuthenticationDisplayName { get; set; } + /// /// Used to indicate if the authentication handler should be registered. This is only done if ANCM indicates /// IIS has a non-anonymous authentication enabled, or for back compat with ANCMs that did not provide this information.