@routr/simpleauth 2.0.8-alpha.3 → 2.0.8-alpha.31

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/dist/envs.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare const BIND_ADDR: string;
2
+ export declare const WHITELIST: string[];
3
+ export declare const METHODS: string[];
4
+ export declare const PATH_TO_AUTH: string;
package/dist/envs.js ADDED
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var _a, _b, _c, _d, _e;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.PATH_TO_AUTH = exports.METHODS = exports.WHITELIST = exports.BIND_ADDR = void 0;
5
+ /*
6
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
7
+ * http://github.com/fonoster
8
+ *
9
+ * This file is part of Routr.
10
+ *
11
+ * Licensed under the MIT License (the "License");
12
+ * you may not use this file except in compliance with
13
+ * the License. You may obtain a copy of the License at
14
+ *
15
+ * https://opensource.org/licenses/MIT
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+ const common_1 = require("@routr/common");
24
+ common_1.Assertions.assertEnvsAreSet(["PATH_TO_AUTH", "METHODS"]);
25
+ exports.BIND_ADDR = (_a = process.env.BIND_ADDR) !== null && _a !== void 0 ? _a : "0.0.0.0:51903";
26
+ exports.WHITELIST = (_c = (_b = process.env.WHITELIST) === null || _b === void 0 ? void 0 : _b.split(",")) !== null && _c !== void 0 ? _c : [];
27
+ exports.METHODS = (_e = (_d = process.env.METHODS) === null || _d === void 0 ? void 0 : _d.split(",")) !== null && _e !== void 0 ? _e : [];
28
+ exports.PATH_TO_AUTH = process.env.PATH_TO_AUTH;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*
4
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
5
+ * http://github.com/fonoster
6
+ *
7
+ * This file is part of Routr.
8
+ *
9
+ * Licensed under the MIT License (the "License");
10
+ * you may not use this file except in compliance with
11
+ * the License. You may obtain a copy of the License at
12
+ *
13
+ * https://opensource.org/licenses/MIT
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ const common_1 = require("@routr/common");
22
+ const envs_1 = require("./envs");
23
+ common_1.HealthCheck.check(envs_1.BIND_ADDR);
package/dist/runner.js CHANGED
@@ -3,10 +3,9 @@
3
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
- var _a;
7
6
  Object.defineProperty(exports, "__esModule", { value: true });
8
7
  /*
9
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
8
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
10
9
  * http://github.com/fonoster/routr
11
10
  *
12
11
  * This file is part of Routr
@@ -26,23 +25,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
25
  // eslint-disable-next-line @typescript-eslint/no-var-requires
27
26
  require("./tracer").init("simpleauth");
28
27
  const service_1 = __importDefault(require("./service"));
29
- const common_1 = require("@routr/common");
30
28
  const logger_1 = require("@fonoster/logger");
29
+ const envs_1 = require("./envs");
31
30
  const logger = (0, logger_1.getLogger)({ service: "simpleauth", filePath: __filename });
32
- common_1.Assertions.assertEnvsAreSet(["PATH_TO_AUTH"]);
33
- const whiteList = process.env.WHITELIST ? process.env.WHITELIST.split(",") : [];
34
31
  try {
35
32
  // eslint-disable-next-line @typescript-eslint/no-var-requires
36
- const users = require(process.env.PATH_TO_AUTH);
33
+ const users = require(envs_1.PATH_TO_AUTH);
37
34
  (0, service_1.default)({
38
- bindAddr: (_a = process.env.BIND_ADDR) !== null && _a !== void 0 ? _a : "0.0.0.0:51903",
39
35
  users,
40
- whiteList
36
+ bindAddr: envs_1.BIND_ADDR,
37
+ whiteList: envs_1.WHITELIST,
38
+ methods: envs_1.METHODS
41
39
  });
42
40
  }
43
41
  catch (e) {
44
42
  if (e.code === "MODULE_NOT_FOUND") {
45
- logger.error(`auth file not found [path = ${process.env.PATH_TO_AUTH}]`);
43
+ logger.error(`auth file not found [path = ${envs_1.PATH_TO_AUTH}]`);
46
44
  }
47
45
  else {
48
46
  logger.error(e);
package/dist/service.d.ts CHANGED
@@ -13,4 +13,5 @@ export default function simpleAuthMiddleware(config: {
13
13
  bindAddr: string;
14
14
  users: User[];
15
15
  whiteList: string[];
16
+ methods: string[];
16
17
  }): void;
package/dist/service.js CHANGED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  /*
8
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
8
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
9
9
  * http://github.com/fonoster/routr
10
10
  *
11
11
  * This file is part of Routr
@@ -23,9 +23,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
23
23
  * limitations under the License.
24
24
  */
25
25
  const api_1 = __importDefault(require("@opentelemetry/api"));
26
- const common_1 = require("@routr/common");
27
- const utils_1 = require("./utils");
28
26
  const processor_1 = __importDefault(require("@routr/processor"));
27
+ const common_1 = require("@routr/common");
29
28
  const logger_1 = require("@fonoster/logger");
30
29
  const logger = (0, logger_1.getLogger)({ service: "simpledata", filePath: __filename });
31
30
  /**
@@ -38,7 +37,7 @@ const logger = (0, logger_1.getLogger)({ service: "simpledata", filePath: __file
38
37
  * @param {string[]} config.whiteList - list of path that required no authentication
39
38
  */
40
39
  function simpleAuthMiddleware(config) {
41
- const { bindAddr, users, whiteList } = config;
40
+ const { bindAddr, users, whiteList, methods } = config;
42
41
  new processor_1.default({ bindAddr, name: "simpleauth" }).listen((req, res) => {
43
42
  const tracer = api_1.default.trace.getTracer("routr-tracer");
44
43
  const currentSpan = api_1.default.trace.getSpan(api_1.default.context.active());
@@ -46,7 +45,7 @@ function simpleAuthMiddleware(config) {
46
45
  logger.silly(JSON.stringify(req, null, " "));
47
46
  const span = tracer.startSpan("server.js:sayHello()", { kind: 1 });
48
47
  // Q: Should we extend the list to other message types?
49
- if (![common_1.CommonTypes.Method.INVITE, common_1.CommonTypes.Method.MESSAGE, common_1.CommonTypes.Method.REGISTER].includes(req.method)) {
48
+ if (!methods.includes(req.method)) {
50
49
  return res.send(req);
51
50
  }
52
51
  if (whiteList.includes(req.message.from.address.uri.user)) {
@@ -59,17 +58,17 @@ function simpleAuthMiddleware(config) {
59
58
  const auth = Object.assign({}, req.message.authorization);
60
59
  auth.method = req.method;
61
60
  // Calculate response and compare with the one send by the endpoint
62
- const calcRes = (0, common_1.calculateAuthResponse)(auth, (0, utils_1.getCredentials)(auth.username, users));
61
+ const calcRes = common_1.Auth.calculateAuthResponse(auth, common_1.Auth.getCredentials(auth.username, users));
63
62
  if (calcRes !== auth.response) {
64
63
  span.addEvent(`user ${req.message.from.address.uri.user} unauthorized to complete request`);
65
64
  span.end();
66
- return res.send((0, utils_1.createUnauthorizedResponse)(auth.realm));
65
+ return res.send(common_1.Auth.createUnauthorizedResponse(req.message.requestUri.host));
67
66
  }
68
67
  }
69
68
  else {
70
69
  span.addEvent(`authorization header not found for user ${req.message.from.address.uri.user}`);
71
70
  span.end();
72
- return res.send((0, utils_1.createUnauthorizedResponse)(req.message.requestUri.host));
71
+ return res.send(common_1.Auth.createUnauthorizedResponse(req.message.requestUri.host));
73
72
  }
74
73
  // Forward request to next middleware
75
74
  span.addEvent(`user ${req.message.from.address.uri.user} authorized`);
package/dist/tracer.js CHANGED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.init = void 0;
7
7
  /*
8
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
8
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
9
9
  * http://github.com/fonoster/routr
10
10
  *
11
11
  * This file is part of Routr
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/simpleauth",
3
- "version": "2.0.8-alpha.3",
3
+ "version": "2.0.8-alpha.31",
4
4
  "description": "This middleware delegates authentication to an external service",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -16,11 +16,12 @@
16
16
  "build": "tsc -b tsconfig.json"
17
17
  },
18
18
  "bin": {
19
- "run_simpleauth": "dist/runner.js"
19
+ "run_simpleauth": "dist/runner.js",
20
+ "healthcheck_simpleauth": "dist/healthcheck.js"
20
21
  },
21
22
  "dependencies": {
22
- "@fonoster/logger": "0.3.18",
23
- "@grpc/grpc-js": "^1.5.9",
23
+ "@fonoster/logger": "0.3.20",
24
+ "@grpc/grpc-js": "^1.8.4",
24
25
  "@opentelemetry/api": "^1.0.4",
25
26
  "@opentelemetry/exporter-jaeger": "^1.0.4",
26
27
  "@opentelemetry/instrumentation": "^0.27.0",
@@ -29,8 +30,8 @@
29
30
  "@opentelemetry/sdk-trace-base": "^1.0.4",
30
31
  "@opentelemetry/sdk-trace-node": "^1.0.4",
31
32
  "@opentelemetry/semantic-conventions": "^1.0.4",
32
- "@routr/common": "^2.0.8-alpha.3",
33
- "@routr/processor": "^2.0.8-alpha.3",
33
+ "@routr/common": "^2.0.8-alpha.31",
34
+ "@routr/processor": "^2.0.8-alpha.31",
34
35
  "google-protobuf": "^3.9.2"
35
36
  },
36
37
  "files": [
@@ -46,5 +47,5 @@
46
47
  "bugs": {
47
48
  "url": "https://github.com/fonoster/routr/issues"
48
49
  },
49
- "gitHead": "aad4c5c31af1fef5e657ee6b445879706757bbbf"
50
+ "gitHead": "6bca271d5a0b7163353a16af6b5195d264b3530f"
50
51
  }
package/dist/utils.d.ts DELETED
@@ -1,19 +0,0 @@
1
- import { User } from "./types";
2
- export declare const getCredentials: (username: string, users: User[]) => User;
3
- export declare const createUnauthorizedResponse: (realm: string, params?: {
4
- qop: string;
5
- algorithm: string;
6
- }) => {
7
- message: {
8
- responseType: number;
9
- wwwAuthenticate: {
10
- scheme: string;
11
- realm: string;
12
- qop: string;
13
- opaque: string;
14
- stale: boolean;
15
- nonce: string;
16
- algorithm: string;
17
- };
18
- };
19
- };
package/dist/utils.js DELETED
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createUnauthorizedResponse = exports.getCredentials = void 0;
4
- /*
5
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster/routr
7
- *
8
- * This file is part of Routr
9
- *
10
- * Licensed under the MIT License (the "License")
11
- * you may not use this file except in compliance with
12
- * the License. You may obtain a copy of the License at
13
- *
14
- * https://opensource.org/licenses/MIT
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- const common_1 = require("@routr/common");
23
- const getCredentials = (username, users) => users.find((user) => user.username === username);
24
- exports.getCredentials = getCredentials;
25
- const createUnauthorizedResponse = (realm, params = { qop: "auth", algorithm: "MD5" }) => {
26
- return {
27
- message: {
28
- // UNAUTHORIZED CODE
29
- responseType: 17,
30
- wwwAuthenticate: {
31
- scheme: "Digest",
32
- realm: realm,
33
- qop: params.qop,
34
- opaque: "",
35
- stale: false,
36
- nonce: (0, common_1.generateNonce)(),
37
- algorithm: params.algorithm
38
- }
39
- }
40
- };
41
- };
42
- exports.createUnauthorizedResponse = createUnauthorizedResponse;