-
-
Save pysco68/a013331155d3e8740610 to your computer and use it in GitHub Desktop.
Ntlm authentication with OWIN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install-Package Pysco68.Owin.Authentication.Ntlm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Pysco68.Owin.Authentication.Ntlm; | |
// considering you already enabled cookie based authentication | |
// Enable NTLM authentication | |
app.UseNtlmAuthentication(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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