

def parse_authorization_header(value):
    'Parse an HTTP basic/digest authorization header transmitted by the web\n    browser.  The return value is either `None` if the header was invalid or\n    not given, otherwise an :class:`~werkzeug.datastructures.Authorization`\n    object.\n\n    :param value: the authorization header to parse.\n    :return: a :class:`~werkzeug.datastructures.Authorization` object or `None`.\n    '
    if (not value):
        return
    value = wsgi_to_bytes(value)
    try:
        (auth_type, auth_info) = value.split(None, 1)
        auth_type = auth_type.lower()
    except ValueError:
        return
    if (auth_type == b'basic'):
        try:
            (username, password) = base64.b64decode(auth_info).split(b':', 1)
        except Exception as e:
            return
        return Authorization('basic', {
            'username': bytes_to_wsgi(username),
            'password': bytes_to_wsgi(password),
        })
    elif (auth_type == b'digest'):
        auth_map = parse_dict_header(auth_info)
        for key in ('username', 'realm', 'nonce', 'uri', 'response'):
            if (not (key in auth_map)):
                return
        if ('qop' in auth_map):
            if ((not auth_map.get('nc')) or (not auth_map.get('cnonce'))):
                return
        return Authorization('digest', auth_map)

dataset/ETHPy150Open Eforcers/gae-flask-todo/lib/werkzeug/http.py parse_authorization_header/original