New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

jwt-in-cookie

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jwt-in-cookie

Wrapper around the functionality of jsonwebtoken to easily set and validate JWT tokens in express requests/responses

latest
npmnpm
Version
1.0.16
Version published
Maintainers
2
Created
Source

Description

Wrapper around the functionality of jsonwebtoken to easily set and validate JWT tokens in express requests/responses

QuickStart

1) Configuration

const jwtInCookie = require("jwt-in-cookie");
jwtInCookie.configure({secret: 'MY_SECRET'});
function (req, res) {
    jwtInCookie.setJwtToken(res, data);
    ...
}

3) Validating JWT in response

function (req, res) {
    jwtInCookie.validateJwtToken(req);
    ...
}

4) Clear JWT token on user-logout

function (req, res) {
    jwtInCookie.clearToken(res);
    ...
}

API

jwtInCookie.configure(config)

config object literal

Configures the instance of jwt-in-cookie

Return: void

  • secret: string (required), secret to be used to sign the JWT

    Eg: abcdefghijklmnopqrstuvwxyz1234567890

  • timeoutDuration: string, length of time before signed data expires

    Eg: "2 hours", "1d", "20h", 60

jwtInCookie.setJwtToken(res, payload, cookieOptions)

Adds payload as a token in the response cookie using configured secret & options

Return: string, token of payload

res express response object

payload object

cookieOptions object, options that set in the cookie

  • httpOnly: boolean, javascript can't access the cookie
  • expires: number, time until the cookie expires (if 0, will expire at end of session)

jwtInCookie.clearToken(res)

Clears the jwt token from the response

Return: void

res express response object

jwtInCookie.validateJwtToken(req)

Returns decoded token if request contains a valid JWT in its cookie (must be preceded by jwtInCookie.configure)

Return: object

req express request object

jwtInCookie.encodePayload(payload)

Encodes payload using configured secret & options

Return: encoded payload

payload object

jwtInCookie.retrieveTokenFromCookie(req)

Retrieves decoded token from the input request's cookie (must be preceded by jwtInCookie.configure)

Return: decoded token

req express request object

Keywords

jwt

FAQs

Package last updated on 11 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts