How to use the cookie-parser.JSONCookies function in cookie-parser

To help you get started, we’ve selected a few cookie-parser 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 danger / peril / api / source / api / auth / getJWTFromRequest.ts View on Github external
export const getJWTFromRequest = (req: any) => {
  // Support JWT via cookies from the user session
  const cookies = (req && req.cookies) || (req && req.headers && req.headers.cookie)
  if (cookies && isString(cookies)) {
    return cookies && parse(cookies).jwt
  }

  if (cookies && cookieParser.JSONCookies(cookies).jwt) {
    return cookieParser.JSONCookies(cookies).jwt
  }

  // Support standard auth: "Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l"
  const basicAuth = req.headers.Authorization || req.headers.authorization
  if (basicAuth) {
    if (basicAuth.includes("Basic ")) {
      return basicAuth.split("Basic ")[1]
    }
  }

  // No other auth routes
  return undefined
}
github qmit-pro / moleculer-api / src / server / application / context / factory / cookie.ts View on Github external
public create({headers}: APIRequestContextSource) {
    if (!headers.cookie) {
      return {};
    }

    const {secrets, ...parseOptions} = this.opts;
    const cookies = parseCookieString(headers.cookie, parseOptions);

    // parse signed cookies
    if (secrets.length !== 0) {
      Object.assign(cookies, signedCookies(cookies, secrets));
    }

    // parse JSON cookies
    return JSONCookies(cookies);
  }
}

cookie-parser

Parse HTTP request cookies

MIT
Latest version published 26 days ago

Package Health Score

89 / 100
Full package analysis