Skip to content

Commit d5cffe7

Browse files
committed
Add NTLM authentication
1 parent ccfeced commit d5cffe7

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from office365.runtime.auth.network_credential_context import NetworkCredentialContext
2+
3+
try:
4+
from requests_ntlm import HttpNtlmAuth
5+
except ImportError:
6+
raise ImportError("To use NTLM authentication the package 'requests_ntlm' needs to be installed")
7+
8+
9+
class NTLMAuthenticationContext(NetworkCredentialContext):
10+
"""Provides NTLM authentication"""
11+
12+
def __init__(self, username, password):
13+
super(NTLMAuthenticationContext, self).__init__(username, password)
14+
self.auth = HttpNtlmAuth(*self.userCredentials)
15+
16+
def authenticate_request(self, request_options):
17+
request_options.auth = self.auth

requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
requests
2+
requests_ntlm [NTLMAuthentication]
3+
setuptools

setup.py

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
long_description_content_type="text/markdown",
2121
url="https://github.com/vgrem/Office365-REST-Python-Client",
2222
install_requires=['requests'],
23+
extras_require={
24+
'NTLMAuthentication': ["requests_ntlm"],
25+
},
2326
tests_require=['nose'],
2427
test_suite='nose.collector',
2528
license="MIT",

0 commit comments

Comments
 (0)