linkedin / pyexchange

Python wrapper for Microsoft Exchange
Apache License 2.0
153 stars 98 forks source link

be authentication agnostic - don't hardcode use of NTLM #39

Closed deronnax closed 2 years ago

deronnax commented 9 years ago

Microsoft Exchange can be configured to use many authentication system (HTTP Basic, HTTP Digest, NTLM, Oauth2). Although NTLM is the first class choice of Exchange, it is far from being the first choice of python dev :) Http auth should be pluggable, the same way it is done in Suds, for example (https://fedorahosted.org/suds/wiki/Documentation#HTTPAUTHENTICATION)

catermelon commented 9 years ago

It already is pluggable, actually, I just don't have anything other than NTLM implemented. :)

To make this work for a different authentication system, you'd have to subclass ExchangeBaseConnection from pyexchange.connection. The only method you must implement is .send(); everything else in the library will call that method.

Then, when you use the library in the code: https://pyexchange.readthedocs.org/en/latest/#setting-up-the-connection

# Set up the connection to Exchange
connection = ExchangeNTLMAuthConnection(url=URL,
                                    username=USERNAME,
                                    password=PASSWORD)

service = Exchange2010Service(connection)

You'd use your own connection class there instead of the NTLM one.

If you want to put some code together for a different auth system, I'm happy to get pull requests.

deronnax commented 9 years ago

Aw OK, thank you for that long reply. I made some tests, and there is only one line change needed to make it work with different auth system provided by requests (https://github.com/linkedin/pyexchange/blob/master/pyexchange/connection.py#L42). I think this class need a bit of a redesign, bevase if I want to implement, say, a ExchangeHTTPBasicConnection or ExchangeHTTPDigestConnection, I will to repeat exactly the 50 lines of code of ExchangeNTLM connection minus one. I think this a bit cumbersome, and I think that from this need we can get out a better connection design :)

catermelon commented 9 years ago

Yeah that seems suboptimal. :)

I am totally happy to have it redesigned - if you want to suggest something since you're currently looking at it, I'm happy to chat about it, or I should have time in the next couple weeks to look.