3.0.1 • Published 12 months ago

token2session v3.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

Token to Session (token2session)

This is an Express middleware that adds a session provided by a JSON Web Token (JWT) to the request object. It can also be used as a security overlay by rejecting invalid tokens.

Installation

Usage in ESM and Typescript:

Usage in commonJs:

Options

* = look at the Notes

OptionTypeDefaultDescription
secretstringSecret used to sign the JWT.
headerKey * (optional)undifined or string"authorization"Header key used to pass the token.
cookieKey * (optional)stringCookie name used to pass the token.
cookieSecret (optional)stringCookie secret used to sign the cookie.
session (optional)string"session"Session name used to store in the req object.
sessionInTokenKey (optional)stringKey if the session is in a sub-object of the decoded token.
useBearer (optional)booleantrueSet to false if you aren't using a bearer token.
rejectOnError (optional)booleantruereject all requests if the token is not valid. Set to false if you want to pass even in case of error.
rejectMessage (optional)string"Unauthorized"Sentence to return on reject.
routeToOmit * (optional)array[]Array of routes that should not be rejected.

Notes

  • If no headerKey or cookieKey is provided and useBearer aren't set to false, the middleware will use the authorization header and assume a bearer token.
  • If no headerKey or cookieKey is provided and useBearer is set to false, an error will be thrown.
  • The routeToOmit option accepts an array of routes that should not be rejected. A route pattern can include a * wildcard to match multiple routes.
3.0.1

12 months ago

3.0.0

12 months ago

2.2.1

1 year ago

2.2.0

1 year ago

2.2.2

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.17

1 year ago

2.0.16

1 year ago

2.0.15

1 year ago

2.0.14

1 year ago

2.0.13

1 year ago

2.0.12

1 year ago

2.0.11

1 year ago

2.0.10

1 year ago

2.0.9

1 year ago

2.0.8

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago