I've been reading a lot of guides/articles but haven't found one yet that does exactly what I want... that is to implement Active Directory Authentication in an ASP.NET Web API through forms.
Something like on this guide:
Cool MVC 5 guide to implement authentication with Active Directory
Which is very good but it's for MVC, i.e., it uses a Controller not an ApiController
Can someone please give me hints/tips/articles on how to start? Especially about the part that connects to the active directory. I've been stuck on this for a while.
UPDATE:
public bool IsAuthenticatedUser(string srvr, string usr, string password)
{
bool authenticated = false;
try {
DirectoryEntry entry = new DirectoryEntry(srvr, usr, password);
object nativeObject = entry.NativeObject;
Object obj = entry.NativeObject;
authenticated = true;
}
catch {
throw new HttpResponseException(HttpStatusCode.Unauthorized);
}
return authenticated;
}
// POST: api/Login
public void Post([FromBody]string username, [FromBody]string password)
{
if (IsAuthenticatedUser("LDAP string", username, password))
{
Redirect("Index");
}
else
{
throw new HttpResponseException(HttpStatusCode.Unauthorized);
}
}
I was thinking of trying something like this for the authentication, your thoughts?