I have an IIS application (AngularJS and PHP), authentication is done with Windows Authentication (Anonymous Authentication is disabled). I would like to have a button that whenever clicked, will lookup active directory users. It works successfully with the code below:
$ldap_server = "ldap://MyDomain.local";
$auth_user = "MyUser@MyDomain";
$auth_pass = "myPass";
$base_dn = "OU=MyDomain, DC=MyDomain, DC=local";
$filter = "(&(objectClass=user)(objectCategory=person)(cn=*))";
if (!($connect=@ldap_connect($ldap_server))) {
die("Could not connect to ldap server");
}
if (!($bind=@ldap_bind($connect, $auth_user, $auth_pass))) {
die("Unable to bind to server: ". ldap_error($connect) . " (" . ldap_errno($connect) . ")");
}
if (!($search=@ldap_search($connect, $base_dn, $filter))) {
die("Unable to search ldap server: ". ldap_error($connect) . " (" . ldap_errno($connect) . ")");
}
However, the user has already supplied credentials when logging in (through IIS Windows Authentication) and I would like to use the same user credentials (or actually impersonating the user). Can I do so without asking for username and password?
I was trying to get server's variables ({$_SERVER['AUTH_USER']} and {$_SERVER['AUTH_PASSWORD']}). Only the user is populated (makes sense...).
I also tried skipping ldap_bind(), calling it only with the $connect parameter but I always get the same error: Unable to search ldap server: Operations error (1)
Of course I can store a dedicated user+pass in PHP, but would like to avoid that and use the logged in user authentication.
Thanks!