How to use the tough-cookie.fromJSON function in tough-cookie

To help you get started, we’ve selected a few tough-cookie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ivanmarban / tough-cookie-file-store / lib / file-store.js View on Github external
}

    if (data) {
        try {
            var dataJson = JSON.parse(data);
        } catch (e) {
            throw new Error('Could not parse cookie file ' + filePath + '. Please ensure it is not corrupted.');
        }
    } else {
        var dataJson = null;
    }

    for (var domainName in dataJson) {
        for (var pathName in dataJson[domainName]) {
            for (var cookieName in dataJson[domainName][pathName]) {
                dataJson[domainName][pathName][cookieName] = tough.fromJSON(JSON.stringify(dataJson[domainName][pathName][cookieName]));
            }
        }
    }
    cb(dataJson);
}
github peterjcaulfield / raiden / lib / cookieFilestore.js View on Github external
dataJson;

        try {
            data = fs.readFileSync(this.filePath);
            dataJson = data ? JSON.parse(data) : null;
        } catch(e) {
            return {};
        }

        for (let domain in dataJson) {

            for (let path in dataJson[domain]) {

                for (let key in dataJson[domain][path]) {

                    dataJson[domain][path][key] = tough.fromJSON(JSON.stringify(dataJson[domain][path][key]));

                }
            }
        }

        return dataJson;
    }
github anypossiblew / railway-client-typescript / dist / src / FileCookieStore.js View on Github external
FileCookieStore.prototype.loadFromFile = function (filePath, option, cb) {
        var data = fs.readFileSync(filePath, { encoding: 'utf8', flag: 'a+' });
        if (option.encrypt && data) {
            var decipher = crypto.createDecipher(option.algorithm || '', option.password || '');
            data = decipher.update(data, 'hex', 'utf8');
            data += decipher.final('utf8');
        }
        var dataJson = data ? JSON.parse(data) : null;
        for (var domainName in dataJson) {
            for (var pathName in dataJson[domainName]) {
                for (var cookieName in dataJson[domainName][pathName]) {
                    dataJson[domainName][pathName][cookieName] = tough.fromJSON(JSON.stringify(dataJson[domainName][pathName][cookieName]));
                }
            }
        }
        cb(dataJson);
    };
    return FileCookieStore;