def parse_authorization_header(value, charset='utf-8'):
    if not value:
        return
    try:
        auth_type, auth_info = value.split(None, 1)
        auth_type = auth_type.lower()
    except ValueError:
        return
    if auth_type == 'basic':
        try:
            up = b64decode(auth_info.encode(DEFAULT_CHARSET)).decode(charset)
            username, password = up.split(':', 1)
        except Exception:
            return
        return BasicAuth(username, password)
    elif auth_type == 'digest':
        auth_map = parse_dict_header(auth_info)
        if not digest_parameters.difference(auth_map):
            return DigestAuth(auth_map.pop('username'), options=auth_map)
Parse an HTTP basic/digest authorisation header.
dataset/ETHPy150Open quantmind/pulsar/pulsar/apps/wsgi/auth.py/parse_authorization_header