Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Windows Challenge

I have a AuthorizationProvider that needs to use both Anonymous and Windows and I can't seem to get then windows challenge to work using:

if (principal == null || principal.Identity == null || string.IsNullOrWhiteSpace(principal.Identity.Name))
            {
                context.OwinContext.Authentication.Challenge();
                return Task.FromResult(0);
            }

Are there any other configuration values I need to set in order for this line to work? : context.OwinContext.Authentication.Challenge();

Any thoughts why this will not work? I need to be able to get the windows principal which works fine with just windows enabled but also need to enable anonymous in order to be able to hit other endpoints in the provider.

like image 519
Fab Avatar asked Aug 25 '17 18:08

Fab


People also ask

How do I enable Windows authentication?

On the taskbar, click Start, and then click Control Panel. In Control Panel, click Programs and Features, and then click Turn Windows Features on or off. Expand Internet Information Services, then World Wide Web Services, then Security. Select Windows Authentication, and then click OK.

How do I turn off Windows authentication in IIS?

To uninstall Windows authentication agent using control panel, perform the following steps: Click Start menu > Control Panel > Programs and Features. Right click NetIQ Windows Authentication Agent and select Uninstall. Click OK to confirm.


1 Answers

In short, you should enable Windows authentication in your Web host. There are different settings, depending on the Web host you are using.

After configuring the Web host, your controller code starts working.

OWIN self-host

Configure HttpListener to accept both authentication modes in OWIN Startup class:

class Startup
{
    public void Configuration(IAppBuilder app)
    {
        var listener = (HttpListener)app.Properties["System.Net.HttpListener"];

        listener.AuthenticationSchemes = 
            AuthenticationSchemes.IntegratedWindowsAuthentication |
            AuthenticationSchemes.Anonymous;

        // Other initialization
    }
}

IIS

If you are hosting your application on IIS, you should enable Windows authentication mode in IIS Web site settings for your application:

enter image description here enter image description here

If you don't see Authentication icon or Windows authentication mode, install following Windows features:

enter image description here

Visual Studio Web debugging (IIS Express)

Finally, for convenience of Web debugging from Visual Studio, you can enable Windows authentication in your project properties. Open Solution explorer and select your project:

enter image description here

Then open Properties tab and set both anonymous and Windows authentication:

enter image description here

For more details, you can check out this article.

like image 106
stop-cran Avatar answered Sep 23 '22 04:09

stop-cran