@opengis/fastify-table 2.5.73 → 2.6.0

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.
@@ -1,7 +1,7 @@
1
1
  export declare function scryptHash(code: string): Promise<string>;
2
2
  export declare function scryptVerify(stored: string, code: string): Promise<boolean>;
3
- export declare function sign(uid: string, secret: string, exp?: number, scopes?: string[]): string;
4
- export declare function verify(token: string, secret: string, scope?: string): {
3
+ export declare function sign(uid: string, secret?: string, exp?: number, scopes?: string[]): string;
4
+ export declare function verify(token: string, secret?: string, scope?: string): {
5
5
  valid: boolean;
6
6
  error: string;
7
7
  payload?: undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/auth/funcs/jwt.ts"],"names":[],"mappings":"AAkBA,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,mBAI5C;AAED,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAI9D;AAED,wBAAgB,IAAI,CAClB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,GAAG,SAAQ,EACX,MAAM,CAAC,EAAE,MAAM,EAAE,UAuBlB;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;EA+CnE;;AAED,wBAAoB"}
1
+ {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/auth/funcs/jwt.ts"],"names":[],"mappings":"AAgBA,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,mBAI5C;AAED,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAI9D;AAED,wBAAgB,IAAI,CAClB,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,MAAM,EACf,GAAG,SAAQ,EACX,MAAM,CAAC,EAAE,MAAM,EAAE,UA8BlB;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;EAmDpE;;AAED,wBAAoB"}
@@ -2,7 +2,7 @@ import { createHmac, scrypt, randomBytes } from "node:crypto";
2
2
  import util from "node:util";
3
3
  import config from "../../../../config.js";
4
4
  const scryptAsync = util.promisify(scrypt);
5
- const { jwtSecret = "65450754381cfaf768eeb4bb33326529b48a40ffdb6e15d84dc224dff527166f", } = config.auth || {};
5
+ const { jwtSecret } = config.auth || {};
6
6
  const jwtHeader = Buffer.from(JSON.stringify({
7
7
  alg: "HS256",
8
8
  type: "JWT",
@@ -18,13 +18,18 @@ export async function scryptVerify(stored, code) {
18
18
  return keyHex === derived.toString("hex");
19
19
  }
20
20
  export function sign(uid, secret, exp = 90000, scopes) {
21
- if (typeof uid !== "string")
21
+ if (!secret && !jwtSecret) {
22
+ throw new Error("environment variable auth.jwtSecret not set");
23
+ }
24
+ if (typeof uid !== "string") {
22
25
  throw new Error("uid must be a string");
26
+ }
23
27
  if (secret && typeof secret !== "string") {
24
28
  throw new Error("secret must be a string");
25
29
  }
26
- if (typeof exp !== "number")
30
+ if (typeof exp !== "number") {
27
31
  throw new Error("exp must be a number");
32
+ }
28
33
  const jwtPayload = Buffer.from(JSON.stringify({
29
34
  uid,
30
35
  scopes,
@@ -38,6 +43,9 @@ export function sign(uid, secret, exp = 90000, scopes) {
38
43
  return `${jwtEncrypted}.${signature}`;
39
44
  }
40
45
  export function verify(token, secret, scope) {
46
+ if (!secret && !jwtSecret) {
47
+ throw new Error("environment variable auth.jwtSecret not set");
48
+ }
41
49
  if (!token) {
42
50
  return { valid: false, error: "not enough params: token" };
43
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"verifyPassword.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/auth/funcs/verifyPassword.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAYpD,wBAA8B,cAAc,CAAC,EAC3C,EAAE,EACF,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;;;;;;eA6CA"}
1
+ {"version":3,"file":"verifyPassword.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/auth/funcs/verifyPassword.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAWpD,wBAA8B,cAAc,CAAC,EAC3C,EAAE,EACF,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;;;;;;eAuCA"}
@@ -33,12 +33,6 @@ export default async function verifyPassword({ pg, username, password, }) {
33
33
  }
34
34
  hash = crypt(hash, json.salt);
35
35
  if (json.password === hash) {
36
- if (username === "admin" && password === "admin") {
37
- await pg.query("update admin.users set password=$2 where uid=$1", [
38
- json.uid,
39
- config.adminPassword || "6Z4gu2mG8R",
40
- ]);
41
- }
42
36
  return { user: json };
43
37
  }
44
38
  return { message: "Wrong password" };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAYxD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAOtD,wBAAsB,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,iBAoIxE;AAED,iBAAS,MAAM,CAAC,OAAO,EAAE,eAAe,QAmCvC;AAED,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAYxD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAYtD,wBAAsB,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,iBAiIxE;AAED,iBAAS,MAAM,CAAC,OAAO,EAAE,eAAe,QAmCvC;AAED,eAAe,MAAM,CAAC"}
@@ -6,8 +6,12 @@ import RedisStore from "fastify-session-redis-store";
6
6
  import config from "../../../config.js";
7
7
  import getRedis from "../redis/funcs/getRedis.js";
8
8
  import { ForbiddenError } from "../../../errors.js";
9
- const fastifyPassport = new Authenticator();
10
9
  const { prefix = "/api" } = config;
10
+ const { secret } = config.auth || {};
11
+ if (!secret) {
12
+ throw new Error("environment variable auth.secret not set");
13
+ }
14
+ const fastifyPassport = new Authenticator();
11
15
  export async function onRequest(req, reply) {
12
16
  const { hostname, headers, routeOptions } = req;
13
17
  const { config: routeConfig, method, handler, url } = routeOptions || {};
@@ -22,10 +26,7 @@ export async function onRequest(req, reply) {
22
26
  ? !!req.headers?.uid &&
23
27
  (process.env.NODE_ENV === "test" || process.env.VITEST)
24
28
  : undefined;
25
- const validToken = (req.ip === "193.239.152.181" ||
26
- req.ip === "127.0.0.1" ||
27
- req.ip?.startsWith?.("192.168.") ||
28
- config.debug) &&
29
+ const validToken = (req.ip === "127.0.0.1" || config.debug) &&
29
30
  (debugAuth ||
30
31
  (req.headers?.token && config.auth?.tokens?.includes?.(headers.token)));
31
32
  if (validToken && !req?.user?.uid) {
@@ -126,7 +127,7 @@ function plugin(fastify) {
126
127
  parseOptions: config?.auth?.cookieOptions || { secure: false },
127
128
  });
128
129
  fastify.register(session, {
129
- secret: config?.auth?.secret || "61b820e12858570a4b0633020d4394a17903d9a9",
130
+ secret: secret,
130
131
  cookieName: "session_auth",
131
132
  cookie: config?.auth?.cookieOptions || { secure: false },
132
133
  store: new RedisStore({
@@ -1,13 +1,13 @@
1
1
  import config from "../../../config.js";
2
2
  import { ForbiddenError } from "../../../errors.js";
3
- const { accessToken = "0NWcGQxKRP8AsRxD" } = config.auth || {};
3
+ const { accessToken } = config.auth || {};
4
4
  /**
5
5
  *
6
6
  * @summary check user access to logger interface - per admin user type or user group
7
7
  * @returns {Object} message, status
8
8
  */
9
9
  export default function checkUserAccess({ user, token, }) {
10
- if (token && token === accessToken) {
10
+ if (token && accessToken && token === accessToken) {
11
11
  return null;
12
12
  }
13
13
  // console.log(user);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/pg/index.ts"],"names":[],"mappings":"AAkCA,iBAAS,MAAM,CAAC,OAAO,EAAE,GAAG,QAwB3B;AAED,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/pg/index.ts"],"names":[],"mappings":"AA+BA,iBAAS,MAAM,CAAC,OAAO,EAAE,GAAG,QAwB3B;AAED,eAAe,MAAM,CAAC"}
@@ -13,10 +13,7 @@ function close() {
13
13
  async function getHeadersPG(req) {
14
14
  if (!req.headers?.token)
15
15
  return null;
16
- const validToken = (req.ip === "193.239.152.181" ||
17
- req.ip === "127.0.0.1" ||
18
- req.ip.startsWith("192.168.") ||
19
- config.debug) &&
16
+ const validToken = (req.ip === "127.0.0.1" || config.debug) &&
20
17
  req.headers?.token &&
21
18
  config.auth?.tokens?.includes?.(req.headers.token);
22
19
  if (validToken && typeof req.headers?.db === "string") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.5.73",
3
+ "version": "2.6.0",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -96,4 +96,4 @@
96
96
  },
97
97
  "author": "Softpro",
98
98
  "license": "ISC"
99
- }
99
+ }