Instantly share code, notes, and snippets.

@pysco68 /0 install.ps1 Secret
Created Jun 21, 2015

Embed
What would you like to do?
Ntlm authentication with OWIN
Install-Package Pysco68.Owin.Authentication.Ntlm
using Pysco68.Owin.Authentication.Ntlm;
// considering you already enabled cookie based authentication
// Enable NTLM authentication
app.UseNtlmAuthentication();
// GET /account/ntlmlogin
[AllowAnonymous]
[Route("ntlmlogin")]
[HttpGet]
public IHttpActionResult Ntlmlogin(string redirectUrl)
{
// create a login challenge if there's no user logged in!
if (this.User == null)
{
var ap = new AuthenticationProperties()
{
RedirectUri = redirectUrl
};
var context = this.Request.GetContext();
// this issues the NTML authentication challenge, which triggers the authentication after
// the 401 answer below (on of the next steps in the OWIN pipeline...)
context.Authentication.Challenge(ap, NtlmAuthenticationDefaults.AuthenticationType);
return Unauthorized();
}
return Redirect(redirectUrl);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment