Browse Source

publish muk_utils - 12.0

pull/9/head
MuK IT GmbH 6 years ago
parent
commit
ef124d5254
  1. 2
      muk_utils/__manifest__.py
  2. 21
      muk_utils/tools/http.py

2
muk_utils/__manifest__.py

@ -20,7 +20,7 @@
{ {
"name": "MuK Utils", "name": "MuK Utils",
"summary": """Utility Features""", "summary": """Utility Features""",
"version": '12.0.1.1.5',
"version": '12.0.1.1.7',
"category": 'Extra Tools', "category": 'Extra Tools',
"license": "AGPL-3", "license": "AGPL-3",
"author": "MuK IT", "author": "MuK IT",

21
muk_utils/tools/http.py

@ -17,12 +17,33 @@
# #
################################################################################### ###################################################################################
import urllib
import base64
import logging import logging
from werkzeug.datastructures import CombinedMultiDict from werkzeug.datastructures import CombinedMultiDict
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
#----------------------------------------------------------
# Header Helper
#----------------------------------------------------------
def decode_http_basic_authentication_value(value):
try:
username, password = base64.b64decode(value).decode().split(':', 1)
return urllib.parse.unquote(username), urllib.parse.unquote(password)
except:
return None, None
def decode_http_basic_authentication(encoded_header):
header_values = encoded_header.strip().split(' ')
if len(header_values) == 1:
return decode_http_basic_authentication_value(header_values[0])
if len(header_values) == 2 and header_values[0].strip().lower() == 'basic':
return decode_http_basic_authentication_value(header_values[1])
return None, None
#---------------------------------------------------------- #----------------------------------------------------------
# Werkzeug Helper # Werkzeug Helper
#---------------------------------------------------------- #----------------------------------------------------------

Loading…
Cancel
Save