From 569639660a88f942424f5da81aa5221ace06831b Mon Sep 17 00:00:00 2001 From: Sergey Mihaylishin Date: Wed, 27 Nov 2024 16:43:10 +0100 Subject: [PATCH] CSC-6138 Migrate auth to new libraries --- office365_api/services.py | 18 +++++++----------- office365_api/v2/client.py | 10 +++------- requirements.txt | 2 -- setup.py | 8 ++------ 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/office365_api/services.py b/office365_api/services.py index cab6acd..f7d865a 100644 --- a/office365_api/services.py +++ b/office365_api/services.py @@ -3,13 +3,9 @@ import logging import urllib.parse -import oauth2client.transport - -from .exceptions import Office365ClientError -from .exceptions import Office365ServerError +from .exceptions import Office365ClientError, Office365ServerError from .filters import BaseFilter - logger = logging.getLogger(__name__) @@ -47,9 +43,11 @@ def get_list(self, filter_backend, path='', custom_headers={}): result.extend(response['value']) next_link = response.get('@odata.nextLink') delta_link = response.get('@odata.deltaLink', '') - delta_link_qs = urllib.parse.parse_qs(urllib.parse.urlparse(delta_link).query) + delta_link_qs = urllib.parse.parse_qs( + urllib.parse.urlparse(delta_link).query) if not next_link and (delta_link_qs.get('$deltaToken') or delta_link_qs.get('$deltatoken')): - delta_token_qs = delta_link_qs.get('$deltaToken') or delta_link_qs.get('$deltatoken') + delta_token_qs = delta_link_qs.get( + '$deltaToken') or delta_link_qs.get('$deltatoken') delta_token = delta_token_qs[0] if delta_token_qs else '' return result, delta_token @@ -59,10 +57,8 @@ def execute_request(self, url, method='get', body=None, headers=None): Try API request; if access_token is expired, request a new one """ logger.info('{}: {}'.format(method.upper(), url)) - resp, content = oauth2client.transport.request(self.client.http, url, - method=method.upper(), - body=body, - headers=headers) + resp, content = self.client.http.request( + url, method=method.upper(), body=body, headers=headers) if resp.status == 200: return json.loads(content) else: diff --git a/office365_api/v2/client.py b/office365_api/v2/client.py index e8c6982..7e56ac5 100644 --- a/office365_api/v2/client.py +++ b/office365_api/v2/client.py @@ -1,15 +1,11 @@ # -*- coding: utf-8 -*- -import requests - from .services import BatchService, SubscriptionFactory, UserServicesFactory class MicrosoftGraphClient(object): - def __init__(self, credentials): - self.credentials = credentials - self.http = None # backward compatibility - self.session = requests.Session() - self.credentials.apply(self.session.headers) + def __init__(self, session): + self.http = None # backward compatibility + self.session = session self.users = UserServicesFactory(self) self.me = self.users('me') diff --git a/requirements.txt b/requirements.txt index 8363b76..e69de29 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +0,0 @@ -oauth2client==4.1.3 -requests>=2.31.0 \ No newline at end of file diff --git a/setup.py b/setup.py index 63b3fdb..2659365 100644 --- a/setup.py +++ b/setup.py @@ -2,12 +2,8 @@ from setuptools import find_packages, setup setup(name='office365-rest-client', - version='3.3.5', - description='Python api wrapper for Office365 API v3.3.5', + version='3.4.0', + description='Python api wrapper for Office365 API v3.4.0', author='SugarCRM', packages=find_packages(), - install_requires=[ - 'oauth2client>=4.0.0', - 'requests>=2.31.0', - ], zip_safe=False)