How to use the tough-cookie.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 postmanlabs / postman-runtime / lib / runner / extensions / event.command.js View on Github external
// cookies for a sub-domain.
                        cookieDomain = getCookieDomain(fnName, args);
                        if (cookieJar && typeof cookieJar.allowProgrammaticAccess === 'function' &&
                            !cookieJar.allowProgrammaticAccess(cookieDomain)) {
                            return self.host.dispatch(dispatchEvent, eventId,
                                `CookieStore: programmatic access to "${cookieDomain}" is denied`);
                        }

                        // serialize cookie object
                        if (fnName === COOKIE_STORE_PUT_METHOD && args[0]) {
                            args[0] = ToughCookie.fromJSON(args[0]);
                        }

                        if (fnName === COOKIE_STORE_UPDATE_METHOD && args[0] && args[1]) {
                            args[0] = ToughCookie.fromJSON(args[0]);
                            args[1] = ToughCookie.fromJSON(args[1]);
                        }

                        // add store method's callback argument
                        args.push(function (err, res) {
                            // serialize error message
                            if (err && err instanceof Error) {
                                err = err.message || String(err);
                            }

                            self.host.dispatch(dispatchEvent, eventId, err, res);
                        });

                        try {
                            cookieStore[fnName].apply(cookieStore, args);
                        }
                        catch (error) {
github postmanlabs / postman-sandbox / lib / sandbox / cookie-store.js View on Github external
return callback(err, cookies.map(function (cookie) {
                    return Cookie.fromJSON(cookie); // serialize cookie object
                }));
            }
github Kong / insomnia / packages / insomnia-cookies / index.js View on Github external
module.exports.cookieToString = function(cookie) {
  // Cookie can either be a plain JS object or Cookie instance
  if (!(cookie instanceof Cookie)) {
    cookie = Cookie.fromJSON(cookie);
  }

  let str = cookie.toString();

  // tough-cookie toString() doesn't put domain on all the time.
  // This hack adds when tough-cookie won't
  if (cookie.domain && cookie.hostOnly) {
    str += '; Domain=' + cookie.domain;
  }

  return str;
};
github postmanlabs / postman-sandbox / lib / sandbox / cookie-store.js View on Github external
// methods: putCookie, updateCookie, removeCookie, removeCookies,
            //          removeAllCookies
            // or, onError
            if (err || !cookies) {
                return callback(err);
            }

            // methods: findCookies, getAllCookies
            if (Array.isArray(cookies)) {
                return callback(err, cookies.map(function (cookie) {
                    return Cookie.fromJSON(cookie); // serialize cookie object
                }));
            }

            // method: findCookie
            callback(err, Cookie.fromJSON(cookies));
        });
github postmanlabs / postman-sandbox / lib / sandbox / cookie-jar.js View on Github external
serialize = function (cookie) {
        if (!cookie) {
            return;
        }

        return ToughCookie.fromJSON({
            key: cookie.name || cookie.key,
            value: cookie.value,
            expires: cookie.expires,
            maxAge: cookie.maxAge,
            domain: cookie.domain,
            path: cookie.path,
            secure: cookie.secure,
            httpOnly: cookie.httpOnly,
            hostOnly: cookie.hostOnly,
            extensions: cookie.extensions
        });
    },
github ayakashi-io / ayakashi / src / bridge / cookies.ts View on Github external
asyncEach(cookies, function(cookieObject, next) {
                const cookie = Cookie.fromJSON(cookieObject);
                if (!cookie) {
                    return next();
                }
                storeJar.setCookie(cookie, getCookieUrl(cookie), next);
            }, function(err) {
                if (err) {
github ayakashi-io / ayakashi / src / bridge / client.ts View on Github external
.map(function(cookie) {
                                return Cookie.fromJSON(cookie);
                            })
                            .filter(function(cookie) {
github ktty1220 / cheerio-httpcli / lib / client.js View on Github external
each(json.cookies, (function (c) {
        this.jar.setCookie(
          Cookie.fromJSON(c).toString(),
          json.response.request.uri.href
        );
      }).bind(this));
    }
github instagrambot / instabot.js / packages / web-api / src / cookies.js View on Github external
    this.values.forEach(x => jar.setCookie(Cookie.fromJSON(x), BASE_URL));
    return jar;
github kognise / repl.it-api / lib.js View on Github external
login(sid) {
    const cookie = Cookie.fromJSON({
      key: 'connect.sid',
      value: sid,
      domain: 'repl.it',
      path: '/'
    })
    return new Promise((resolve, reject) => {
      this.jar.setCookie(cookie, 'https://repl.it/', (error) => {
        if (error) return reject(error)
        resolve()
      })
    })
  }