Python code used for AD authentication
I'm using the Python library ldap to write a client for authentication on a Microsoft Active Directory.
I'm using with success the following code:
uri = "ldap://active.directory.server:389" con = ldap.initialize(uri, bytes_mode = False) con.protocol_version = ldap.VERSION3 con.set_option(ldap.OPT_REFERRALS, ldap.OPT_OFF) con.set_option(ldap.OPT_NETWORK_TIMEOUT, timeout = 3) bindDistinguishedName = "mydomain\\myuser" bind_result = con.simple_bind_s(bindDistinguishedName, "mypassword") By this post I have understand that in the previous code I'm using the (legacy) format:
- <Domain NetBIOS Name>\<sAMAccountName>
Use of the FQDN for bind DN
I have tested the previous code by setting the bindDistinguishedName with UserPrincipalName (UPN) as showed below:
bindDistinguishedName = "[email protected]" (as well explained here, mydomain.com is called FQDN, where FQDN stands for Fully Qualified Domain Name).
The authentication has been completed with success also in this case.
FQDN not allowed in NetBIOS form
In the UPN mode I have added the .com after mydomain, so I have tested the NetBIOS form with the value mydomain.com as showed below:
bindDistinguishedName = "mydomain.com\\myuser" but the authentication fails.
Why in the NetBIOS form the .com part of the FQDN is not allowed? If for example FQDN is equal to mydomain.mycompany.com the NetBIOS form is only mydomain?
Why in the NetBIOS form the .com part of the FQDN is not allowed?That was really a design and implementation decision from Microsoft 25 years ago. There are now traditionally two well known formats: UPN or DomainShortname\username. Adding a third would have been trivial, but no-one was asking for it yet, and they wanted to persuade people to adopt UPN usage. Also as an FYI, in the near future, the code you provided will not be able to authenticate on port 389. A TLS secured port will be required, such as 636 or 3269.LDAPSon port 636 (or 3269), but I have written in the question my code forLDAPauthentication. I have got in my code a parameter to select between LDAP or LDAPS.