Skip to content

Commit b620f72

Browse files
Daniel BarkerDaniel Barker
authored andcommitted
Added NTLM authentication
1 parent 5698da1 commit b620f72

File tree

5 files changed

+33
-9
lines changed

5 files changed

+33
-9
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
.idea/
33
build/
44
osisoft.pidevclub.piwebapi.egg-info/
5+
credentials.py
6+
test/dcb_tests.py
7+
58

69
# Byte-compiled / optimized / DLL files
710
__pycache__/

osisoft/pidevclub/piwebapi/api_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# coding: utf-8
22
from requests.auth import HTTPBasicAuth
33
from requests_kerberos import HTTPKerberosAuth, OPTIONAL
4+
from requests_ntlm import HttpNtlmAuth
45
"""
56
Copyright 2017 OSIsoft, LLC
67
Licensed under the Apache License, Version 2.0 (the "License");
@@ -82,16 +83,15 @@ def user_agent(self, value):
8283
self.default_headers['User-Agent'] = value
8384

8485

85-
8686
def set_kerberos_auth(self):
8787
self.rest_client.auth = HTTPKerberosAuth(force_preemptive=True, mutual_authentication=OPTIONAL, delegate=True)
8888

89-
89+
def set_ntlm_auth(self, username, password):
90+
self.rest_client.auth = HttpNtlmAuth(username, password)
9091

9192
def set_basic_auth(self, username, password):
9293
self.rest_client.auth = HTTPBasicAuth(username, password)
9394

94-
9595
def set_default_header(self, header_name, header_value):
9696
self.default_headers[header_name] = header_value
9797

osisoft/pidevclub/piwebapi/pi_web_api_client.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,26 @@
6262
class PIWebApiClient(object):
6363
__baseUrl = None
6464
__useKerberos = True
65+
__useNtlm = False
6566
__username = None
6667
__password = None
6768
__verifySsl = True
6869
__config = None
69-
def __init__(self, baseUrl, useKerberos = True, username = None, password = None, verifySsl = True):
70+
71+
def __init__(self, baseUrl, useKerberos=True, username=None, password=None, verifySsl=True, useNtlm=False):
7072
self.__baseUrl = baseUrl
7173
self.__useKerberos = useKerberos
74+
self.__useNtlm = useNtlm
7275
self.__username = username
7376
self.__password = password
7477
self.__verifySsl = verifySsl
7578
self.__api_client = api_client.ApiClient(self.__baseUrl, self.__verifySsl)
76-
if (self.__useKerberos == True):
79+
if self.__useKerberos is True:
7780
self.__api_client.set_kerberos_auth()
81+
elif self.__useNtlm is True:
82+
self.__api_client.set_ntlm_auth(username, password)
7883
else:
7984
self.__api_client.set_basic_auth(self.__username, self.__password)
80-
8185
self.__homeApi = HomeApi(self.__api_client)
8286
self.__analysisApi = AnalysisApi(self.__api_client)
8387
self.__analysisCategoryApi = AnalysisCategoryApi(self.__api_client)

requirements.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,19 @@ six == 1.8.0
33
setuptools >= 21.0.0
44
requests >= 2.18.4
55
requests-kerberos >= 0.12.0
6-
6+
asn1crypto==0.24.0
7+
certifi==2018.4.16
8+
cffi==1.11.5
9+
chardet==3.0.4
10+
cryptography==2.2.2
11+
idna==2.6
12+
ntlm-auth==1.1.0
13+
numpy==1.14.3
14+
pycparser==2.18
15+
python-dateutil==2.7.3
16+
pytz==2018.4
17+
requests-ntlm==1.1.0
18+
six==1.8.0
19+
urllib3==1.22
20+
wincertstore==0.2
21+
winkerberos==0.7.0

test/test_main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
class TestMain(unittest.TestCase):
3131

3232
def getPIWebApiClient(self):
33-
return PIWebApiClient("https://devdata.osisoft.com/piwebapi", useKerberos=False, username="webapiuser", password="!try3.14webapi!", verifySsl=False)
33+
return PIWebApiClient("https://devdata.osisoft.com/piwebapi", useKerberos=False, username="webapiuser",
34+
password="!try3.14webapi!", verifySsl=False)
3435

3536

3637
def test_getHome(self):
@@ -111,7 +112,8 @@ def test_getExceptionError(self):
111112
pass
112113

113114
def test_getBatch(self):
114-
client = PIWebApiClient("https://marc-rras.osisoft.int/piwebapi", useKerberos=False, username="marc.adm", password="kk", verifySsl=False)
115+
client = PIWebApiClient("https://marc-rras.osisoft.int/piwebapi", useKerberos=False, username="marc.adm",
116+
password="kk", verifySsl=False)
115117
landing = client.home.get();
116118
req1 = PIRequest()
117119
req2 = PIRequest()

0 commit comments

Comments
 (0)