Skip to content

Instantly share code, notes, and snippets.

@amalgjose
Created February 2, 2023 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amalgjose/71009d46e01d6111db0dfd58383cd010 to your computer and use it in GitHub Desktop.
Save amalgjose/71009d46e01d6111db0dfd58383cd010 to your computer and use it in GitHub Desktop.
test code
import ldap
ldap_host = ""
pem_file_loc = ""
ldap_bind_dn = ""
conn = ldap.initialize(ldap_host)
conn.protocol_version = ldap.VERSION3
conn.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_DEMAND)
conn.set_option(ldap.OPT_X_TLS_CACERTFILE, pem_file_loc)
conn.set_option(ldap.OPT_X_TLS_NEWCTX, 0)
conn.simple_bind_s(ldap_bind_dn, 'ldap_password')
result = conn.search_s('dc=somedomain,dc=com',
ldap.SCOPE_SUBTREE,
'userPrincipalName=user@somedomain.com',
['memberOf'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment