From 78870b9ba34c0498ca65e7ef14b772d43e1a56ef Mon Sep 17 00:00:00 2001 From: Erik Cederstrand Date: Thu, 10 Nov 2022 11:50:19 +0100 Subject: [PATCH] Also replace ResolveNames with ConvertId for service auth type guessing. --- exchangelib/protocol.py | 3 +-- exchangelib/transport.py | 18 ++++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/exchangelib/protocol.py b/exchangelib/protocol.py index d03d080..fb8df51 100644 --- a/exchangelib/protocol.py +++ b/exchangelib/protocol.py @@ -222,8 +222,7 @@ def __init__(self, *args, **kwargs): # Autodetect authentication type if necessary # pylint: disable=access-member-before-definition if self.auth_type is None: - self.auth_type = get_service_authtype(service_endpoint=self.service_endpoint, versions=API_VERSIONS, - name=self.credentials.username) + self.auth_type = get_service_authtype(service_endpoint=self.service_endpoint, versions=API_VERSIONS) # Try to behave nicely with the Exchange server. We want to keep the connection open between requests. # We also want to re-use sessions, to avoid the NTLM auth handshake on every request. diff --git a/exchangelib/transport.py b/exchangelib/transport.py index e07ac54..da9b711 100644 --- a/exchangelib/transport.py +++ b/exchangelib/transport.py @@ -115,7 +115,7 @@ def get_autodiscover_authtype(service_endpoint, data): return _get_auth_method_from_response(response=r) -def get_service_authtype(service_endpoint, versions, name): +def get_service_authtype(service_endpoint, versions): # Get auth type by tasting headers from the server. Only do POST requests. HEAD is too error prone, and some servers # are set up to redirect to OWA on all requests except POST to /EWS/Exchange.asmx log.debug('Getting service auth type for %s', service_endpoint) @@ -124,7 +124,7 @@ def get_service_authtype(service_endpoint, versions, name): from .protocol import BaseProtocol with BaseProtocol.raw_session() as s: for version in versions: - data = dummy_xml(version=version, name=name) + data = dummy_xml(version=version) log.debug('Requesting %s from %s', data, service_endpoint) r = s.post(url=service_endpoint, headers=DEFAULT_HEADERS.copy(), data=data, allow_redirects=True, timeout=BaseProtocol.TIMEOUT) @@ -197,13 +197,11 @@ def _tokenize(val): return auth_tokens -def dummy_xml(version, name): +def dummy_xml(version): # Generate a minimal, valid EWS request - from .services import ResolveNames # Avoid circular import - return wrap(content=ResolveNames(protocol=None).get_payload( - unresolved_entries=[name], - parent_folders=None, - return_full_contact_data=False, - search_scope=None, - contact_data_shape=None, + from .properties import ENTRY_ID, EWS_ID, AlternateId + from .services import ConvertId + return wrap(content=ConvertId(protocol=None).get_payload( + items=[AlternateId(id="DUMMY", format=EWS_ID, mailbox="DUMMY")], + destination_format=ENTRY_ID, ), version=version)