@routr/simpleauth 2.0.8-alpha.2 → 2.0.8-alpha.20

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/runner.js CHANGED
@@ -3,7 +3,7 @@
3
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
- var _a;
6
+ var _a, _b, _c, _d, _e;
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  /*
9
9
  * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
@@ -29,15 +29,17 @@ const service_1 = __importDefault(require("./service"));
29
29
  const common_1 = require("@routr/common");
30
30
  const logger_1 = require("@fonoster/logger");
31
31
  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(",") : [];
32
+ common_1.Assertions.assertEnvsAreSet(["PATH_TO_AUTH", "METHODS"]);
33
+ const whiteList = (_b = (_a = process.env.WHITELIST) === null || _a === void 0 ? void 0 : _a.split(",")) !== null && _b !== void 0 ? _b : [];
34
+ const methods = (_d = (_c = process.env.METHODS) === null || _c === void 0 ? void 0 : _c.split(",")) !== null && _d !== void 0 ? _d : [];
34
35
  try {
35
36
  // eslint-disable-next-line @typescript-eslint/no-var-requires
36
37
  const users = require(process.env.PATH_TO_AUTH);
37
38
  (0, service_1.default)({
38
- bindAddr: (_a = process.env.BIND_ADDR) !== null && _a !== void 0 ? _a : "0.0.0.0:51903",
39
+ bindAddr: (_e = process.env.BIND_ADDR) !== null && _e !== void 0 ? _e : "0.0.0.0:51903",
39
40
  users,
40
- whiteList
41
+ whiteList,
42
+ methods
41
43
  });
42
44
  }
43
45
  catch (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
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/simpleauth",
3
- "version": "2.0.8-alpha.2",
3
+ "version": "2.0.8-alpha.20",
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",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@fonoster/logger": "0.3.18",
23
- "@grpc/grpc-js": "^1.5.9",
23
+ "@grpc/grpc-js": "^1.8.4",
24
24
  "@opentelemetry/api": "^1.0.4",
25
25
  "@opentelemetry/exporter-jaeger": "^1.0.4",
26
26
  "@opentelemetry/instrumentation": "^0.27.0",
@@ -29,8 +29,8 @@
29
29
  "@opentelemetry/sdk-trace-base": "^1.0.4",
30
30
  "@opentelemetry/sdk-trace-node": "^1.0.4",
31
31
  "@opentelemetry/semantic-conventions": "^1.0.4",
32
- "@routr/common": "^2.0.8-alpha.2",
33
- "@routr/processor": "^2.0.8-alpha.2",
32
+ "@routr/common": "^2.0.8-alpha.20",
33
+ "@routr/processor": "^2.0.8-alpha.20",
34
34
  "google-protobuf": "^3.9.2"
35
35
  },
36
36
  "files": [
@@ -46,5 +46,5 @@
46
46
  "bugs": {
47
47
  "url": "https://github.com/fonoster/routr/issues"
48
48
  },
49
- "gitHead": "28ab976b0ef8b5cd34e278ea6fda13c518d7d052"
49
+ "gitHead": "a22ee8342d03f5dfe46fddba89ffe3e6d0d5deb6"
50
50
  }
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;