I am using Python ldap3[1] to build an API that allows users to change their Microsoft Active Directory passwords using their current credentials. This is what my API is doing:
1- Create LDAP connect and bind to LDAP server:
tls_config = Tls(validate=ssl.CERT_NONE)
server = Server(ldaps_endpoint, port = 636, use_ssl = True, tls = tls_config)
connection = Connection(server, user=username, password=password, authentication='NTLM')
connection.bind()
2- Change password using extend.microsoft.modifyPassword.ad_modify_password()
ldap3 function:
user_modified = extend.microsoft.modifyPassword.ad_modify_password(connection, user_dn, new_password, current_password)
This works fine when the user flag change password on next logon is not set. When it is set, it does not work because the connection fails to bind()
. I tried using an ANONYMOUS
connection instead of NTLM
which binds successfully. However, the ad_modify_password()
function fails with:
In order to perform this operation a successful bind must be completed on the connection
How is ad_modify_password()
supposed to work with change password on next logon flag?