How can I connect throw php to an active directory, and make user authentication ? I have tried LDAP locally using WAMP but no success so far, maybe doing it wrong ?
I tried this:
$link = ldap_connect( 'domain.com' ); // Your domain or domain server
if( ! $link )
{
// Could not connect to server - handle error appropriately
}
ldap_set_option( $link, LDAP_OPT_PROTOCOL_VERSION, 3 ); // Recommended for AD
// Now try to authenticate with credentials provided by user
if ( ! ldap_bind( $link, 'username@domain.com', 'SomeSecret' ) )
{
// Invalid credentials! Handle error appropriately
}
// Bind was successful - continue
changing the domain for my active directory domain "davidecuriosidade.onmicrosoft.com", but as I said no success. Is any configuration on my active directory ?
When you BIND to LDAP, you are binding to a DN, and not a classical "username"/"password" combination.
This DN is written in an LDAP format, which is unique to the setup in your Active Directory configuration.
Therefore instead of username@domain.com
It becomes more like: sAMAccountName=myuser,ou=GroupAllowed,dc=domain,dc=com
That is assuming in your Active Directory setup you have a "group" (Organizational Unit) name "GroupAllowed" and that "myuser" is the account name of the user in that group. Additionally that "domain" is the domain name of the AD environment and "com" is the TLD for the domain.