https://github.com/do-/node-doix-http-cookie-jwt
doix http cookie based sessions using jwt
https://github.com/do-/node-doix-http-cookie-jwt
Last synced: about 1 month ago
JSON representation
doix http cookie based sessions using jwt
- Host: GitHub
- URL: https://github.com/do-/node-doix-http-cookie-jwt
- Owner: do-
- License: other
- Created: 2024-01-05T19:38:54.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-07T16:17:36.000Z (over 1 year ago)
- Last Synced: 2025-10-09T21:37:35.766Z (6 months ago)
- Language: JavaScript
- Size: 133 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README


`node-doix-http-cookie-jwt` is a plug in for the [`doix`](https://github.com/do-/node-doix) framework providing an HTTP cookie based session mechanism using [JSON Web Tokens](https://jwt.io/).
Here, the whole user information record (seen as `this.user` in each [Job](https://github.com/do-/node-doix/wiki/Job) instance) is completely included in the cookie value as the `sub` property of the JSON Web Token's `claim`.
# Installation
```
npm install doix-http-cookie-jwt
```
# Usage
Upon instantiating your [WebService](https://github.com/do-/node-doix-http/wiki/WebService) descendant as `myWebService`:
```js
const {CookieJWT} = require ('doix-http-cookie-jwt')
const sessionProvider = new CookieJWT ({
// name: 'sid',
// ttl: 60,
// claim: {},
// sign: {},
// verify: {},
})
// sessionProvider.getPrivateKey = async () => {...}
// sessionProvider.getPublicKey = async () => {...}
sessionProvider.plugInto (myWebService)
```
# Options
| Name | Type | Default | Description | Note
| ---- | -- | -- | -- | -- |
| `name` | String | `'sid'` | name of the cookie |
| `ttl` | int | 60 | time to live, in minutes | defines the `expiresIn` JWT property
| `claim` | Object | `{}` | the claim part of the JWT | the `sub` property is always overridden with the user info
| `sign` | Object | `{}` | options for [sign ()](https://github.com/auth0/node-jsonwebtoken#jwtsignpayload-secretorprivatekey-options-callback) |
| `verify` | Object | `{}` | options for [verify ()](https://github.com/auth0/node-jsonwebtoken#jwtverifytoken-secretorpublickey-options-callback) |
# Methods
| Name | Description | Default implementation
| ---- | -- | --
| `getPrivateKey ()` | returns the private key for using with [sign ()](https://github.com/auth0/node-jsonwebtoken#jwtsignpayload-secretorprivatekey-options-callback) | `' '`
| `getPublicKey ()` | returns the public key for using with [verify ()](https://github.com/auth0/node-jsonwebtoken#jwtverifytoken-secretorpublickey-options-callback) | `' '`