Skip to content

Commit

Permalink
Remove sessionEphemeral
Browse files Browse the repository at this point in the history
Switch to use sessionLength instead. Setting the length
to 0 will indicate an ephemeral session, reducing the
need for an additional key.
  • Loading branch information
joshcanhelp committed Jan 3, 2020
1 parent dc2be1a commit 08e6702
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
3 changes: 1 addition & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ Additional configuration keys that can be passed to `auth()` on initialization:
- **`redirectUriPath`** - Relative path to the application callback to process the response from the authorization server. This value is combined with the `baseUrl` and sent to the authorize endpoint as the `redirectUri` parameter. Default is `/callback`.
- **`required`** - Use a boolean value to require authentication for all routes. Pass a function instead to base this value on the request. Default is `true`.
- **`routes`** - Boolean value to automatically install the login and logout routes. See [the examples](EXAMPLES.md) for more information on how this key is used. Default is `true`.
- **`sessionLength`** - Integer value, in seconds, indicating application session length. Default is 7 days.
- **`sessionLength`** - Integer value, in seconds, indicating application session length. Set to `0` to indicate the cookie should be ephemeral (no expiration). Default is 7 days.
- **`sessionName`** - String value for the cookie name used for the internal session. This value must only include letters, numbers, and underscores. Default is `identity`.
- **`sessionEphemeral`** - Use a boolean to indicate the cookie should be ephemeral (no expiration on the cookie). Default is `false`.

### Authorization Params Key

Expand Down
10 changes: 8 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ const paramsSchema = Joi.object().keys({
logoutPath: Joi.string().optional().default('/logout'),
legacySameSiteCookie: Joi.boolean().optional().default(true),
sessionName: Joi.string().token().optional().default('identity'),
sessionSecret: Joi.alternatives([ Joi.array().items(Joi.string()), Joi.string(), Joi.boolean().valid([false]) ]).required().default(),
sessionSecret: Joi.alternatives([
// Array of keys to allow for rotation.
Joi.array().items(Joi.string()),
// Single string key.
Joi.string(),
// False to stop client session from being created.
Joi.boolean().valid([false])
]).required(),
sessionLength: Joi.number().integer().optional().default(7 * 24 * 60 * 60),
sessionEphemeral: Joi.boolean().optional().default(false),

idpLogout: Joi.boolean().optional().default(false)
.when('auth0Logout', { is: true, then: Joi.boolean().optional().default(true) })
Expand Down
9 changes: 2 additions & 7 deletions lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const hkdf = require('futoin-hkdf');
const deriveKey = (secret) => hkdf(secret, 32, { info: 'JWE CEK', hash: 'SHA-256' });
const epoch = () => Date.now() / 1000 | 0;

module.exports = ({ cookieName, propertyName, secret, duration, ephemeral, cookieOptions = {} }) => {
module.exports = ({ cookieName, propertyName, secret, duration, cookieOptions = {} }) => {
let current;

const { domain, httpOnly, path, secure, sameSite } = cookieOptions;
Expand Down Expand Up @@ -52,11 +52,6 @@ module.exports = ({ cookieName, propertyName, secret, duration, ephemeral, cooki
if (req[propertyName] && Object.keys(req[propertyName]).length > 0) {
const value = encrypt(JSON.stringify(req[propertyName]), { iat, uat, exp });

// TODO: chunk
// if (Buffer.byteLength(value) >= 4050) {
//
// }

res.cookie(
cookieName,
value,
Expand All @@ -66,7 +61,7 @@ module.exports = ({ cookieName, propertyName, secret, duration, ephemeral, cooki
path,
secure,
sameSite,
expires: ephemeral ? 0 : new Date(exp * 1000)
expires: !duration ? 0 : new Date(exp * 1000)
}
);
}
Expand Down
1 change: 0 additions & 1 deletion middleware/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ module.exports = function (params) {
propertyName: config.sessionName,
secret: config.sessionSecret,
duration: config.sessionLength,
ephemeral: config.sessionEphemeral,
// TODO: cookieOptions: { domain, httpOnly, path, secure, sameSite }
}));
}
Expand Down

0 comments on commit 08e6702

Please sign in to comment.