Skip to content

Instantly share code, notes, and snippets.

@pysco68
Created June 21, 2015 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pysco68/a013331155d3e8740610 to your computer and use it in GitHub Desktop.
Save pysco68/a013331155d3e8740610 to your computer and use it in GitHub Desktop.
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