@apolitical/server 2.5.5 → 2.5.6-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apolitical/server",
3
- "version": "2.5.5",
3
+ "version": "2.5.6-rc.1",
4
4
  "description": "Node.js module to encapsulate Apolitical's express server setup",
5
5
  "author": "Apolitical Group Limited <engineering@apolitical.co>",
6
6
  "license": "MIT",
@@ -6,8 +6,9 @@ module.exports = ({ jwtEncodeHelper, config }) => {
6
6
  APOLITICAL: { ISSUER, ADMIN_ROLE, COOKIE_KEY },
7
7
  } = config.JWT;
8
8
 
9
- function generateAdminToken() {
10
- const token = jwtEncodeHelper(SESSION_SECRET, {
9
+ function generateAdminToken(sessionSecret) {
10
+ const secret = SESSION_SECRET || sessionSecret;
11
+ const token = jwtEncodeHelper(secret, {
11
12
  role: ADMIN_ROLE,
12
13
  admin: true,
13
14
  iss: ISSUER,
@@ -16,11 +17,11 @@ module.exports = ({ jwtEncodeHelper, config }) => {
16
17
  return token;
17
18
  }
18
19
 
19
- function buildHeaders({ authToken }) {
20
+ function buildHeaders({ authToken }, sessionSecret) {
20
21
  const headers = {};
21
22
  if (authToken && typeof authToken === 'boolean') {
22
23
  // When authToken is a boolean then generate an admin token
23
- const adminToken = generateAdminToken();
24
+ const adminToken = generateAdminToken(sessionSecret);
24
25
  Object.assign(headers, { Cookie: `${COOKIE_KEY}=${adminToken}` });
25
26
  } else if (authToken && typeof authToken === 'string') {
26
27
  // When authToken is a string then use the it as the token
@@ -29,10 +30,10 @@ module.exports = ({ jwtEncodeHelper, config }) => {
29
30
  return headers;
30
31
  }
31
32
 
32
- function buildOptions({ headers, params, validateStatus, data }) {
33
+ function buildOptions({ headers, params, validateStatus, data, sessionSecret }) {
33
34
  const opts = {};
34
35
  if (headers) {
35
- Object.assign(opts, { headers: buildHeaders(headers) });
36
+ Object.assign(opts, { headers: buildHeaders(headers, sessionSecret) });
36
37
  }
37
38
  if (params) {
38
39
  Object.assign(opts, { params });