From 7b79589e8332bb6029eec582baf9b347aeb78ce8 Mon Sep 17 00:00:00 2001 From: i223t Date: Tue, 26 May 2020 12:52:44 +0200 Subject: [PATCH] Add enable\disable\force password change directory methods --- O365/directory.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/O365/directory.py b/O365/directory.py index 4d328f50..05da0e2a 100644 --- a/O365/directory.py +++ b/O365/directory.py @@ -322,3 +322,37 @@ def get_current_user(self, query=None): url = self.build_url('') # target main_resource return self._get_user(url, query=query) + + def disable_user(self, user): + """ Disables user by it's id or user principal name + + :param str user: the user id or user principal name + """ + url = self.build_url(self._endpoints.get('get_user').format(email=user)) + data = {'accountEnabled': False} + response = self.con.patch(url, data=data, headers={'Content-Type': 'application/json'}) + + return bool(response) + + def enable_user(self, user): + """ Enables user by it's id or user principal name + + :param str user: the user id or user principal name + """ + url = self.build_url(self._endpoints.get('get_user').format(email=user)) + data = {'accountEnabled': True} + response = self.con.patch(url, data=data, headers={'Content-Type': 'application/json'}) + + return bool(response) + + def force_change_password(self, user): + """ Forces user to change his password on the next logon + + :param str user: the user id or user principal name + """ + + url = self.build_url(self._endpoints.get('get_user').format(email=user)) + data = {'passwordProfile': {'forceChangePasswordNextSignIn': True}} + response = self.con.patch(url, data=data, headers={'Content-Type': 'application/json'}) + + return bool(response)