Cookies don't get attached even after using storage API

189 Views Asked by At
const iframe = document.createElement("iframe");
iframe.sandbox.add('allow-scripts', 'allow-storage-access-by-user-activation', 'allow-same-origin');
iframe.onload = function () {
    window.addEventListener('load', () => {
        document.getElementById('test-button').addEventListener('click', () => {
            getStorageAccess().then(_ => {
                var xhr = new XMLHttpRequest();
                xhr.open('POST', 'https://example.net/v1/set-key-authorization-cookie/cb325a10-9404-4f77-b615-319415fa945a', true);
                xhr.setRequestHeader('Content-Type', 'application/json');
                xhr.withCredentials = true;
                xhr.send('{"KeyAuthorizationToken": "eyJhbGciOiJFUzI1NiIsImtpZCI6Ij"}');
                xhr.onreadystatechange = function () {
                    if (this.readyState == this.HEADERS_RECEIVED && this.status == 200) {
                        var xhr2 = new XMLHttpRequest();
                        xhr2.open('GET', 'https://example.net/v1/get-key/cb325a10-9404-4f77-b615-319415fa945a?encrypted-key-container=eyJhbGciOiJFUzI1Ni', true);
                        xhr2.withCredentials = true;
                        xhr2.send(null);
                    }
                }
            });
            console.log("The iframe is loaded" + getStorageAccess());
        });
    });
};
document.body.appendChild(iframe);

My inner request xhr2 needs some cookies from xhr request. getStorageAccess promise is resolved but no cookies in request.

0

There are 0 best solutions below