Skip to content

Commit

Permalink
CSC-6138 Migrate auth to new libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
smihaylishin-sugarcrm authored and amatsukov-sugarcrm committed Nov 27, 2024
1 parent 10835b5 commit 5696396
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
18 changes: 7 additions & 11 deletions office365_api/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
10 changes: 3 additions & 7 deletions office365_api/v2/client.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
oauth2client==4.1.3
requests>=2.31.0
8 changes: 2 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 5696396

Please sign in to comment.