From 54b37ee0075d670eb2f0f8bc5b2db43a35a7dd25 Mon Sep 17 00:00:00 2001 From: Pierre Jochem Date: Thu, 28 Jul 2016 15:28:11 +0200 Subject: [PATCH] NTLM Auth NTLM auth opener --- sharepoint/auth.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sharepoint/auth.py b/sharepoint/auth.py index 0fac642..62be1b8 100644 --- a/sharepoint/auth.py +++ b/sharepoint/auth.py @@ -5,6 +5,7 @@ except ImportError: from urllib2 import BaseHandler, HTTPPasswordMgrWithDefaultRealm, build_opener +from ntlm import HTTPNtlmAuthHandler class PreemptiveBasicAuthHandler(BaseHandler): @@ -31,3 +32,9 @@ def basic_auth_opener(url, username, password): auth_handler = PreemptiveBasicAuthHandler(password_manager) opener = build_opener(auth_handler) return opener + +def ntlm_auth_opener(url, user, password): + password_manager = HTTPPasswordMgrWithDefaultRealm() + password_manager.add_password(None, url, user, password) + auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(password_manager) + return build_opener(auth_NTLM)