4.0.0 • Published 1 year ago
token2session v4.0.0
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
headerKeyorcookieKeyis provided anduseBeareraren't set to false, the middleware will use the authorization header and assume a bearer token. - If no
headerKeyorcookieKeyis provided anduseBeareris set to false, an error will be thrown. - The
routeToOmitoption accepts an array of routes that should not be rejected. A route pattern can include a * wildcard to match multiple routes.
4.0.0
1 year ago
3.0.1
2 years ago
3.0.0
2 years ago
2.2.1
3 years ago
2.2.0
3 years ago
2.2.2
3 years ago
2.1.4
3 years ago
2.1.3
3 years ago
2.1.2
3 years ago
2.1.1
3 years ago
2.1.0
3 years ago
2.0.17
3 years ago
2.0.16
3 years ago
2.0.15
3 years ago
2.0.14
3 years ago
2.0.13
3 years ago
2.0.12
3 years ago
2.0.11
3 years ago
2.0.10
3 years ago
2.0.9
3 years ago
2.0.8
3 years ago
2.0.7
3 years ago
2.0.6
3 years ago
2.0.5
3 years ago
2.0.4
3 years ago
2.0.3
3 years ago
2.0.2
3 years ago
2.0.1
3 years ago
2.0.0
3 years ago
1.0.0
3 years ago