@routr/simpleauth 2.0.5-alpha.15 → 2.0.5-alpha.16
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 +14 -9
- package/dist/service.d.ts +11 -2
- package/dist/service.js +21 -10
- package/dist/tracer.d.ts +6 -0
- package/dist/tracer.js +10 -6
- package/dist/utils.js +5 -5
- package/package.json +5 -5
package/dist/runner.js
CHANGED
|
@@ -22,23 +22,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
* See the License for the specific language governing permissions and
|
|
23
23
|
* limitations under the License.
|
|
24
24
|
*/
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
25
26
|
require("./tracer").init("simpleauth");
|
|
26
|
-
const logger_1 = __importDefault(require("@fonoster/logger"));
|
|
27
27
|
const service_1 = __importDefault(require("./service"));
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const whiteList = process.env.WHITELIST ? process.env.WHITELIST.split(
|
|
28
|
+
const common_1 = require("@routr/common");
|
|
29
|
+
const logger_1 = require("@fonoster/logger");
|
|
30
|
+
const logger = (0, logger_1.getLogger)({ service: "simpleauth", filePath: __filename });
|
|
31
|
+
common_1.Assertions.assertEnvsAreSet(["PATH_TO_AUTH"]);
|
|
32
|
+
const whiteList = process.env.WHITELIST ? process.env.WHITELIST.split(",") : [];
|
|
33
33
|
try {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
34
35
|
const users = require(process.env.PATH_TO_AUTH);
|
|
35
|
-
(0, service_1.default)({
|
|
36
|
+
(0, service_1.default)({
|
|
37
|
+
bindAddr: process.env.BIND_ADDR || "0.0.0.0:51903",
|
|
38
|
+
users,
|
|
39
|
+
whiteList
|
|
40
|
+
});
|
|
36
41
|
}
|
|
37
42
|
catch (e) {
|
|
38
43
|
if (e.code === "MODULE_NOT_FOUND") {
|
|
39
|
-
|
|
44
|
+
logger.error(`auth file not found [path = ${process.env.PATH_TO_AUTH}]`);
|
|
40
45
|
}
|
|
41
46
|
else {
|
|
42
|
-
|
|
47
|
+
logger.error(e);
|
|
43
48
|
}
|
|
44
49
|
}
|
package/dist/service.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { User } from
|
|
3
|
-
|
|
2
|
+
import { User } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* A simple authentication middleware that authenticates users based on a list of users
|
|
5
|
+
* or whitelisted endpoints paths.
|
|
6
|
+
*
|
|
7
|
+
* @param {MiddlewareConfig} config - configuration for the middleware
|
|
8
|
+
* @param {string} config.bindAddr - address to bind to
|
|
9
|
+
* @param {User[]} config.users - list of users
|
|
10
|
+
* @param {string[]} config.whiteList - list of path that required no authentication
|
|
11
|
+
*/
|
|
12
|
+
export default function simpleAuthMiddleware(config: {
|
|
4
13
|
bindAddr: string;
|
|
5
14
|
users: User[];
|
|
6
15
|
whiteList: string[];
|
package/dist/service.js
CHANGED
|
@@ -23,21 +23,32 @@ 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 logger_1 = __importDefault(require("@fonoster/logger"));
|
|
27
26
|
const common_1 = require("@routr/common");
|
|
28
27
|
const utils_1 = require("./utils");
|
|
29
28
|
const processor_1 = __importDefault(require("@routr/processor"));
|
|
30
|
-
|
|
29
|
+
const logger_1 = require("@fonoster/logger");
|
|
30
|
+
const logger = (0, logger_1.getLogger)({ service: "simpledata", filePath: __filename });
|
|
31
|
+
/**
|
|
32
|
+
* A simple authentication middleware that authenticates users based on a list of users
|
|
33
|
+
* or whitelisted endpoints paths.
|
|
34
|
+
*
|
|
35
|
+
* @param {MiddlewareConfig} config - configuration for the middleware
|
|
36
|
+
* @param {string} config.bindAddr - address to bind to
|
|
37
|
+
* @param {User[]} config.users - list of users
|
|
38
|
+
* @param {string[]} config.whiteList - list of path that required no authentication
|
|
39
|
+
*/
|
|
40
|
+
function simpleAuthMiddleware(config) {
|
|
31
41
|
const { bindAddr, users, whiteList } = config;
|
|
32
|
-
new processor_1.default({ bindAddr, name: "simpleauth" })
|
|
33
|
-
.listen((req, res) => {
|
|
34
|
-
logger_1.default.verbose(`authenticating ${req.message.from.address.uri.user} endpoint with simpleauth`);
|
|
35
|
-
logger_1.default.silly(JSON.stringify(req, null, ' '));
|
|
42
|
+
new processor_1.default({ bindAddr, name: "simpleauth" }).listen((req, res) => {
|
|
36
43
|
const tracer = api_1.default.trace.getTracer("routr-tracer");
|
|
37
44
|
const currentSpan = api_1.default.trace.getSpan(api_1.default.context.active());
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const span = tracer.startSpan(
|
|
45
|
+
logger.silly(`authenticating ${req.message.from.address.uri.user} endpoint with simpleauth`, { traceId: currentSpan === null || currentSpan === void 0 ? void 0 : currentSpan.spanContext().traceId });
|
|
46
|
+
logger.silly(JSON.stringify(req, null, " "));
|
|
47
|
+
const span = tracer.startSpan("server.js:sayHello()", { kind: 1 });
|
|
48
|
+
// Consider extending 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)) {
|
|
50
|
+
return res.send(req);
|
|
51
|
+
}
|
|
41
52
|
if (whiteList.includes(req.message.from.address.uri.user)) {
|
|
42
53
|
span.addEvent(`authenticated ${req.message.from.address.uri.user} from whitelist`);
|
|
43
54
|
span.end();
|
|
@@ -66,4 +77,4 @@ function SimpleAuthProcessor(config) {
|
|
|
66
77
|
res.send(req);
|
|
67
78
|
});
|
|
68
79
|
}
|
|
69
|
-
exports.default =
|
|
80
|
+
exports.default = simpleAuthMiddleware;
|
package/dist/tracer.d.ts
CHANGED
package/dist/tracer.js
CHANGED
|
@@ -30,20 +30,24 @@ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
|
30
30
|
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
31
31
|
const exporter_jaeger_1 = require("@opentelemetry/exporter-jaeger");
|
|
32
32
|
const instrumentation_grpc_1 = require("@opentelemetry/instrumentation-grpc");
|
|
33
|
+
/**
|
|
34
|
+
* This function registers the instrumentations for the service.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} serviceName - The name of the service.
|
|
37
|
+
* @return {Tracer} The tracer object.
|
|
38
|
+
*/
|
|
33
39
|
function init(serviceName) {
|
|
34
40
|
const provider = new sdk_trace_node_1.NodeTracerProvider({
|
|
35
41
|
resource: new resources_1.Resource({
|
|
36
|
-
[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: serviceName
|
|
37
|
-
})
|
|
42
|
+
[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: serviceName
|
|
43
|
+
})
|
|
38
44
|
});
|
|
39
45
|
const exporter = new exporter_jaeger_1.JaegerExporter();
|
|
40
46
|
provider.addSpanProcessor(new sdk_trace_base_1.SimpleSpanProcessor(exporter));
|
|
41
47
|
provider.register();
|
|
42
48
|
(0, instrumentation_1.registerInstrumentations)({
|
|
43
|
-
instrumentations: [
|
|
44
|
-
new instrumentation_grpc_1.GrpcInstrumentation(),
|
|
45
|
-
],
|
|
49
|
+
instrumentations: [new instrumentation_grpc_1.GrpcInstrumentation()]
|
|
46
50
|
});
|
|
47
|
-
return api_1.default.trace.getTracer(
|
|
51
|
+
return api_1.default.trace.getTracer("routr-tracer");
|
|
48
52
|
}
|
|
49
53
|
exports.init = init;
|
package/dist/utils.js
CHANGED
|
@@ -20,7 +20,7 @@ exports.createUnauthorizedResponse = exports.getCredentials = void 0;
|
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
22
|
const common_1 = require("@routr/common");
|
|
23
|
-
const getCredentials = (username, users) => users.find(user => user.username === username);
|
|
23
|
+
const getCredentials = (username, users) => users.find((user) => user.username === username);
|
|
24
24
|
exports.getCredentials = getCredentials;
|
|
25
25
|
const createUnauthorizedResponse = (realm, params = { qop: "auth", algorithm: "MD5" }) => {
|
|
26
26
|
return {
|
|
@@ -28,18 +28,18 @@ const createUnauthorizedResponse = (realm, params = { qop: "auth", algorithm: "M
|
|
|
28
28
|
// UNAUTHORIZED CODE
|
|
29
29
|
responseType: 17,
|
|
30
30
|
wwwAuthenticate: {
|
|
31
|
-
scheme:
|
|
31
|
+
scheme: "Digest",
|
|
32
32
|
realm: realm,
|
|
33
33
|
qop: params.qop,
|
|
34
|
-
opaque:
|
|
34
|
+
opaque: "",
|
|
35
35
|
stale: false,
|
|
36
36
|
nonce: (0, common_1.generateNonce)(),
|
|
37
37
|
algorithm: params.algorithm
|
|
38
38
|
},
|
|
39
39
|
extensions: [
|
|
40
40
|
{
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
name: "Expires",
|
|
42
|
+
value: 0
|
|
43
43
|
}
|
|
44
44
|
]
|
|
45
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routr/simpleauth",
|
|
3
|
-
"version": "2.0.5-alpha.
|
|
3
|
+
"version": "2.0.5-alpha.16",
|
|
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",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"run_simpleauth": "dist/runner.js"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@fonoster/logger": "
|
|
22
|
+
"@fonoster/logger": "0.3.17-alpha.2",
|
|
23
23
|
"@grpc/grpc-js": "^1.5.9",
|
|
24
24
|
"@opentelemetry/api": "^1.0.4",
|
|
25
25
|
"@opentelemetry/exporter-jaeger": "^1.0.4",
|
|
@@ -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.5-alpha.
|
|
33
|
-
"@routr/processor": "^2.0.5-alpha.
|
|
32
|
+
"@routr/common": "^2.0.5-alpha.16",
|
|
33
|
+
"@routr/processor": "^2.0.5-alpha.16",
|
|
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": "
|
|
49
|
+
"gitHead": "b40323ac18cc3872b168bf4e8273f5bdb3f7510a"
|
|
50
50
|
}
|