aspnet / HttpSysServer

[Archived] A web server for ASP.NET Core based on the Windows Http Server API. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
106 stars 39 forks source link

Hosting in http.sys does not allow both anonymous and Windows authentication to coexist #394

Closed artisticcheese closed 7 years ago

artisticcheese commented 7 years ago

Code below does not work in http.sys while working in IIS where both anonymous and Windows authentication is specified and access to individual methods are based of tags

namespace Plain.Controllers
{
    [Authorize]
    public class HomeController : Controller
    {
        [Authorize]
        public IActionResult Windows()
        {
            return Content ("You are " + User.Identity.Name +  "; Authentication Type:" + User.Identity.AuthenticationType );
        }

        [AllowAnonymous]
        public IActionResult Anonymous()
        {
            return Content ("You are " + User.Identity.Name +  "; Authentication Type:" + User.Identity.AuthenticationType );;
        }
    }

}
 options.Authentication.Schemes =  AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM;
            options.Authentication.AllowAnonymous = true;
artisticcheese commented 7 years ago

Documentation needs to be updated that services section shall contain following statement to allow both anonymous and Windows to work together

services.AddAuthentication(Microsoft.AspNetCore.Server.IISIntegration.IISDefaults.AuthenticationScheme);
Tratcher commented 7 years ago

Note HttpSys has it's own constant for this, HttpSysDefaults.AuthenticationScheme though the value happens to the be same as the one from IISDefaults.

artisticcheese commented 7 years ago

@Tratcher So I need to do services.AddAuthentication(Microsoft.AspNetCore.Server.HttpSysDefaults.AuthenticationScheme);?

Tratcher commented 7 years ago

Yes, otherwise [Authorize] will give you an error about no default scheme set.