Package: tinyLDAP3
tinyLDAP3Tiny wrapper for Python `ldap3` Package.Table of ContentsAbout The ProjectInstallationUsageInstance CreateObject DetailObject ReadObjects SearchPerson AuthCustomizationLicenseContactAbout The ProjectLorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam aliquam pretium mi quis laoreet.(back to top)InstallationInstallation is as simple as:pipinstalltinyLDAP3(back to top)UsageInstance CreateCreate a new instance of thetinyLDAP3Clientclass and assigns this object to the local variableldap.Optional Instance Attributes:connect_timeout: int- Default value 10 (sec.)receive_timeout: int- Default value 10 (sec.)Don't store sensitive information in source code. For example use ".env" file.fromtinyLDAP3importtinyLDAP3ClientfromtypingimportIterableLDAP_USER_DN:str="CN=Your-LDAP-Account,OU=_SpecialUsers,DC=example,DC=com"LDAP_USER_PASSWORD:str="You%wILL#&neVeR!gUEss"LDAP_SEARCH_BASE:str="DC=example,DC=com"LDAP_HOSTS:Iterable=["10.10.10.2","10.10.20.2","10.10.30.2"]if__name__=="__main__":ldap=tinyLDAP3Client(user_dn=LDAP_USER_DN,user_pass=LDAP_USER_PASSWORD,search_base=LDAP_SEARCH_BASE,hosts=LDAP_HOSTS)(back to top)Object Detailobject_category- Three categories are expected:Computer,GrouporPerson.Predefined list of returned attributesCategory: ComputercndescriptiondistinguishedNamelastLogonlogonCountnameobjectGUIDoperatingSystemoperatingSystemVersionsAMAccountNamesAMAccountTypeservicePrincipalNamewhenChangedwhenCreatedCategory: GroupcndescriptiondistinguishedNamemailmembermemberOfnameobjectGUIDsAMAccountNamesAMAccountTypewhenChangedwhenCreatedCategory: PersonaccountExpiresbadPasswordTimebadPwdCountcncompanydepartmentdisplayNameemployeeIDemployeeNumberextensionAttribute12extensionAttribute5extensionAttribute6extensionAttribute9ipPhonellastLogofflastLogonlockoutTimelogonCountmailmanagermemberOfmobilemsDS-UserPasswordExpiryTimeComputedmsExchExtensionAttribute22msExchExtensionAttribute23msExchExtensionCustomAttribute1msExchExtensionCustomAttribute2objectGUIDpwdLastSetsAMAccountNamesAMAccountTypeservicePrincipalNamestreetAddresstelephoneNumberthumbnailPhototitleuserAccountControluserPrincipalNamewhenChangedwhenCreatedOptional arguments:is_active: bool = False- Define the search scope: Active or All Users.returned_attrs_collection: Iterable[str] = None- Override the collection of predefined returned attributes.Computerldap=...print("Result:",ldap.object_detail(object_category="computer",attr_name="sAMAccountName",attr_value="value",returned_attrs_collection=["description","sAMAccountName","mail","distinguishedName"]))# Result: {#     'operatingSystem': None,#     'sAMAccountName': 'value',#     'whenCreated': datetime.datetime(...),#     'lastLogon': None,#     'cn': '...'# }Groupldap=...print("Result:",ldap.object_detail(object_category="group",attr_name="sAMAccountName",attr_value="value",returned_attrs_collection=["description","sAMAccountName","mail","distinguishedName"]))# Result: {'mail': None, 'sAMAccountName': 'value', 'description': '...', 'distinguishedName': '...', 'cn': '...'}Personldap=...# Unique valueprint("Result:",ldap.object_detail(object_category="person",attr_name="sAMAccountName",attr_value="unique_value",returned_attrs_collection=["sAMAccountName","mail","employeeNumber"]))# Result: {'mail': '...', 'sAMAccountName': 'unique_value', 'employeeNumber': '...'}print("Result",ldap.object_detail(object_category="person",attr_name="sn",attr_value="value",returned_attrs_collection=["sAMAccountName","mail","employeeNumber"]))# WARNING:root:@ LDAP Object Detail @ - 'ObjectCategory: `person`, AttrName: `sn`, Value: `value`' \# - More than one LDAP Object were found. Use attributes with unique values.# Result: (#     {'mail': '...', 'employeeNumber': '...', 'sAMAccountName': '...', 'sn': 'value'},#     {'mail': '...', 'employeeNumber': '...', 'sAMAccountName': '...', 'sn': 'value'}# )(back to top)Object ReadReading object attributes by category anddistinguishedNameattribute value.returned_attrs_collection: Iterable[str] = None- Override the collection of returned attributes (Default: All attributes).ldap=...print("Result:",ldap.object_read(object_category=["top","person","user"],dn="CN=Any-LDAP-Account,OU=_Users,DC=example,DC=com",returned_attrs_collection=["objectClass","description","sAMAccountName","name","objectGUID"]))# Result: {#     'objectClass': ['top', 'person', 'organizationalPerson', 'user'],#     'description': None,#     'name': '...',#     'objectGUID': '{...-...-...-...-...}',#     'sAMAccountName': '...'# }(back to top)Objects Searchobject_category- Three categories are expected:Computer,GrouporPerson.Predefined list of attributes for Person (User) searchCategory: PersoncnemployeeNumberipPhonemailmobilesAMAccountNamePredefined list of returned attributesCategory: ComputercnoperatingSystemoperatingSystemVersionwhenChangedwhenCreatedCategory: GroupdistinguishedNamemailsAMAccountNamewhenChangedwhenCreatedCategory: PersondepartmentdisplayNameemployeeNumberipPhonemailmobilesAMAccountNametitleuserAccountControlwhenChangedwhenCreatedCategory searching:Computer- wildcard:*value*Group- wildcard:*value*Person- wildcard:value*Optional method arguments:order_by: str = "sAMAccountName"-  Sorting by a specific attribute. Default valuesAMAccountname.
The attribute will be added automatically if it's missing from the collection of returned attributes.search_by_attrs_collection: Iterable[str] = None- Override the predefined list for Person (User) search.returned_attrs_collection: Iterable[str] = None- Override the predefined list of returned attributes.Computerldap=...print("Result:",ldap.objects_search(object_category="computer",attr_value="value",returned_attrs_collection=["cn","lastLogon","operatingSystem"]))# Result: (#     {'sAMAccountName': '...', 'cn': 'value', 'lastLogon': datetime.datetime(...), 'operatingSystem': '...'},#     ...,#     {'sAMAccountName': '...', 'cn': 'value', 'lastLogon': None, 'operatingSystem': '...'},# )Groupldap=...print("Result:",ldap.objects_search(object_category="group",attr_value="value",returned_attrs_collection=["sAMAccountName","distinguishedName"]))# Result: (#     {'distinguishedName': 'CN=...', 'sAMAccountName': 'value'},#     ...,#     {'distinguishedName': 'CN=...', 'sAMAccountName': 'value'},# )Personldap=...print("Result",ldap.objects_search(object_category="person",attr_value="value",order_by="displayName",returned_attrs_collection=["mail"]))# Result: ({'mail': None, 'displayName': '...'}, ..., {'mail': '...', 'displayName': '...'}(back to top)Person Authlogin- Expected value of theuserPrincipalNameattribute.Predefined list of returned attributes:"cn","employeeNumber","ipPhone","mail","mobile","userPrincipalName","sAMAccountName",Optional method arguments:returned_attrs_collection: Iterable[str] = None- Override the predefined list of returned attributes.ldap=...print(ldap.person_auth(login="login@example.com",password="***",))# Result Auth Pass:# (#     True,#     {#         'ipPhone': '...',#         'userPrincipalName': 'login@example.com',#         'mobile': '...',#         'employeeNumber': '...',#         'mail': '...',#         'cn': '...',#         'sAMAccountName': '...'#     }# )# Result Auth Failed:# (#     False,#     {#         'result': 49,#         'description': 'invalidCredentials',#         'dn': '',#         'message': '80090308: LdapErr: DSID-0C09056B, comment: AcceptSecurityContext error, data 52e, v4f7c\x00',#         'referrals': None,#         'saslCreds': None,#         'type': 'bindResponse'#     }# )(back to top)CustomizationOverriding_search_limitinstance attributes:fromtinyLDAP3importtinyLDAP3ClientclasstinyLDAP3Custom(tinyLDAP3Client):def__init__(self,**kwargs):super().__init__(**kwargs)self._search_limit=1000(back to top)LicenseDistributed under the MIT License. SeeLICENSEfor more information.(back to top)ContactLuarvick -lu.luarvick@gmail.comProject Link:https://github.com/luarvick/tinyLDAP3(back to top)