Skip to content

Commit

Permalink
Merge pull request #86 from ecederstrand/replace-resolvenames-with-co…
Browse files Browse the repository at this point in the history
…nvertid-2

Also replace ResolveNames with ConvertId for service auth type guessing
  • Loading branch information
ajay-k authored Dec 1, 2022
2 parents 6dfe9d6 + 78870b9 commit 65ec3de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
3 changes: 1 addition & 2 deletions exchangelib/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 8 additions & 10 deletions exchangelib/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)

0 comments on commit 65ec3de

Please sign in to comment.