How to use the cookie.parse function in cookie

To help you get started, we’ve selected a few 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 physiii / open-automation / server / socket.js View on Github external
return;
			}

			console.log(TAG, 'Device connected.', device_id);

			// Update the socket on the device.
			device.setGatewaySocket(socket, device_token);

			// Return because the rest of this function is for connections to the client API.
			return;
		}


		// Client API

		const cookies = socket.handshake.headers.cookie ? cookie.parse(socket.handshake.headers.cookie) : {};

		// TODO: Allow passing access_token through query params for non-browser clients (e.g. native apps).
		if (!cookies.access_token) {
			handleAuthenticationError('no access token');
			return;
		}

		function verifyAccessToken () {
			return new Promise((resolve, reject) => {
				jwt.verify(cookies.access_token, jwt_secret, {issuer: config.api_token_issuer}, (error, claims) => {
					if (error) {
						reject();
						handleAuthenticationError('invalid access token ' + error.name);
						return;
					}
github rapid7 / guardian / lib / mw / cookie.js View on Github external
// Add Set-Cookie headers before request ends
    res.cookies = {};
    res.before('headers', function() {
      this.setHeader('Set-Cookie', Object.keys(res.cookies).map(function(name) {
        return res.cookies[name].serialize();
      }));
    });

    // No request cookies. Carry on.
    if (!req.headers.cookie) {
      req.cookies = {};
      return next();
    }

    req.cookies = CookieCodec.parse(req.headers.cookie || '');

    next();
  });
};
github nathschmidt / restify-cookies / test / testutils / request.js View on Github external
var req = http.get(opts, function(resp){
			var cookies = cookie.parse(resp.headers['set-cookie'].join('; '));
			fn(null, cookies);
		});
github adonisjs / adonis-framework / packages / cookie / src / Cookie / index.ts View on Github external
export function parse (
  cookieHeader: string,
  secretKey?: string,
): { signedCookies: { [key: string]: any }, plainCookies: { [key: string]: any } } {
  const output = { signedCookies: {}, plainCookies: {} }
  if (!cookieHeader) {
    return output
  }

  const parsed = cookie.parse(cookieHeader)

  return Object.keys(parsed).reduce((result, key: string) => {
    const unpacked = unpack(parsed[key], secretKey)
    if (unpacked === null) {
      return result
    }

    if (unpacked.signed) {
      result.signedCookies[key] = unpacked.value
    } else {
      result.plainCookies[key] = unpacked.value
    }

    return result
  }, output)
}
github ctrlplusb / zeit-now-node-server / src / index.ts View on Github external
function parseCookie(req: IncomingMessage): NowRequestCookies {
  const header: undefined | string | string[] = req.headers.cookie;
  if (!header) {
    return {};
  }
  return parse(Array.isArray(header) ? header.join(';') : header);
}
github aredotna / ervell / src / v2 / apollo / localState / clientData.ts View on Github external
export default () => {
  const {
    data: sharifyData,
    data: { CURRENT_USER, CURRENT_URL },
  } = sharify;

  const token = CURRENT_USER && CURRENT_USER.authentication_token;
  const currentRoute = { ...url.parse(CURRENT_URL || window.location.href) };
  const isLoggedIn = !!(CURRENT_USER && CURRENT_USER.id);
  const cookies = cookie.parse(document.cookie);

  return {
    token,
    currentRoute,
    isLoggedIn,
    cookies,
    serializedMe: serializedMe(CURRENT_USER),
    sharifyData,
  };
};
github vtex-apps / store-graphql / node / resolvers / auth / index.ts View on Github external
const setVtexIdAuthCookie = (ioContext: any, response: any, headers: any, authStatus: any) => {
  if (authStatus === 'Success') {
    const authAccount = `VtexIdclientAutCookie_${ioContext.account}`
    const authCookie = parse(headers['set-cookie'].find((checkAuth: any) => {
      return checkAuth.includes(authAccount)
    }))
    const VTEXID_EXPIRES = Math.round((new Date(authCookie.expires).getTime() - Date.now()) / 1000)
    response.set('Set-Cookie', serialize(authAccount, authCookie[authAccount], {
      httpOnly: true,
      maxAge: VTEXID_EXPIRES,
      path: '/',
      secure: true
    }))
  }
  return authStatus
}
/** Password must have at least eight characters with at least one number,
github superfly / fly / v8env / ts / cookie_jar.ts View on Github external
function parseCookie(cookieStr: string): { [key: string]: string }[] {
  let options: { [s: string]: string } = {}
  let cookies = []
  let parsed = cookie.parse(cookieStr)
  for (let attr in parsed) {
    if (cookieAttributeNames.indexOf(attr) != -1) {
      options[attr] = String(parsed[attr])
      continue
    }
    cookies.push({ name: attr, value: parsed[attr] })
  }
  return cookies.map((c) => Object.assign(c, options))
}
github ecordell / macaroon-session-example / app / static / scripts / main.js View on Github external
function getMaxRefreshTime() {
  var cookies = cookie.parse(document.cookie);
  if (cookies['max_refresh_time']) {
    return moment(cookies['max_refresh_time']).toDate();
  } else {
    return null;
  }
}