Commit c0e25299 authored by Michael Ströder's avatar Michael Ströder

aligned with class OTPWebService in ekca-service>=0.1.3

parent 02c04cf2
......@@ -14,46 +14,41 @@ class PrivacyIdeaOTPChecker(OTPWebService):
"""
Check OTP against web service of privacyIDEA
"""
req_mime_type = 'application/json'
def check(self, username, otp):
"""
Check OTP against web service of privacyIDEA
"""
# create a password manager
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
# Add the username and password
password_mgr.add_password(
None,
self._cfg['OTP_CHECK_URL'],
self._cfg['OTP_CHECK_USER'],
self._cfg['OTP_CHECK_PASSWORD']
check_url = self._cfg[self.cfg_key_url]
url_opener = urllib.request.build_opener(
urllib.request.HTTPSHandler(
debuglevel=self._cfg.get('OTP_CHECK_HTTPS_DEBUG_LEVEL', 0),
context=self._ssl_context(),
check_hostname=None,
),
)
auth_handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
opener = urllib.request.build_opener(auth_handler)
urllib.request.install_opener(opener)
otp_check_request = urllib.request.Request(
self._cfg['OTP_CHECK_URL'],
data=('{ "username" : "' + username + '", "password" : "' + otp + '" }').encode(),
headers={
'Content-Type': 'application/json',
},
check_url,
data=json.dumps(dict(username=username, password=otp)).encode('utf-8'),
headers={'Content-Type': self.req_mime_type},
method='POST',
)
res_data = None
try:
result = opener.open(otp_check_request)
result = url_opener.open(otp_check_request)
res_data = json.loads(result.read().decode('utf-8'))
except urllib.error.URLError as err:
self._log.warning(
'Connect to %r failed: %r / response data: %r',
self._cfg['OTP_CHECK_URL'],
check_url,
err,
res_data,
)
raise OTPCheckFailed(
'OTP check failed against {0!r}: {1}'.format(
self._cfg['OTP_CHECK_URL'],
check_url,
err,
)
)
......
......@@ -34,7 +34,7 @@ setup(
data_files=[],
install_requires=[
'setuptools',
'ekca-service>=0.1.2',
'ekca-service>=0.1.3',
'ldap3>=2.4',
],
zip_safe=False,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment