function handleLogout(sp_urls, final_url) {

    const request_urls = sp_urls.filter(function(current_url) {
        return current_url.indexOf('SAMLRequest') > 0;
    });

    const response_urls = sp_urls.filter(function(current_url) {
        return current_url.indexOf('SAMLResponse') > 0;
    });

    function kill_session() {
        const current_url = window.location.href;
        if (current_url.indexOf('?logout') == -1 && current_url.indexOf('&logout') == -1) {
            console.log("current URL does not terminate the IDP session");
            let logout_url = '';
            if (current_url.indexOf('?') > 0) {
                logout_url = current_url + "&logout";
            } else {
            }
            fetch(logout_url, {
                method: 'GET',
                credentials: 'include'
            }).then(response => {
                if (!response.ok) {
                    console.error('Logout request failed');
                }
            }).catch(error => {
                console.error('Logout request error', error);
            });
        }
    }

    const requests = request_urls.map(current_url => {
        return fetch(current_url, {
            method: 'GET',
            credentials: 'include',
            mode: 'cors'
        }).then(response => {
            if (!response.ok) {
                console.error('Request failed', current_url);
            }
        }).catch(error => {
            console.error('Request error', current_url, error);
        });
    });

    // send out the requests in parallel
    // in any case we then terminate the IDP session and redirect to the correct destination
    // we have to complete the logout no matter if the requests were successful or if there were failed requests
    Promise.allSettled(requests).then(() => {
        kill_session(); // required to terminate IDP session
    }).finally(() => {
        if (response_urls.length == 0) {
            // redirect to root location on the IDP
            console.log('Finish IDP-initiated SAML logout - redirecting to: ' + final_url);
            window.location.href = final_url;
        } else {
            // only 1 such URL allowed. process ends on SP side
            console.log('Finish SP-initiated SAML logout - redirecting to: ' + response_urls[0]);
            window.location.href = response_urls[0];
        }
    })
}