3.0.1 • Published 12 months ago
token2session v3.0.1
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
Option | Type | Default | Description |
---|---|---|---|
secret | string | Secret used to sign the JWT. | |
headerKey * (optional) | undifined or string | "authorization" | Header key used to pass the token. |
cookieKey * (optional) | string | Cookie name used to pass the token. | |
cookieSecret (optional) | string | Cookie secret used to sign the cookie. | |
session (optional) | string | "session" | Session name used to store in the req object. |
sessionInTokenKey (optional) | string | Key if the session is in a sub-object of the decoded token. | |
useBearer (optional) | boolean | true | Set to false if you aren't using a bearer token. |
rejectOnError (optional) | boolean | true | reject 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
orcookieKey
is provided anduseBearer
aren't set to false, the middleware will use the authorization header and assume a bearer token. - If no
headerKey
orcookieKey
is provided anduseBearer
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