diff --git a/muk_utils/__manifest__.py b/muk_utils/__manifest__.py index 8031286..94ceeb6 100644 --- a/muk_utils/__manifest__.py +++ b/muk_utils/__manifest__.py @@ -20,7 +20,7 @@ { "name": "MuK Utils", "summary": """Utility Features""", - "version": '12.0.1.1.5', + "version": '12.0.1.1.7', "category": 'Extra Tools', "license": "AGPL-3", "author": "MuK IT", diff --git a/muk_utils/tools/http.py b/muk_utils/tools/http.py index a8c5ae6..6504569 100644 --- a/muk_utils/tools/http.py +++ b/muk_utils/tools/http.py @@ -17,12 +17,33 @@ # ################################################################################### +import urllib +import base64 import logging from werkzeug.datastructures import CombinedMultiDict _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 #----------------------------------------------------------