@routr/simpleauth 2.0.5-alpha.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Fonoster Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/runner.js ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ /*
8
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
9
+ * http://github.com/fonoster/routr
10
+ *
11
+ * This file is part of Routr
12
+ *
13
+ * Licensed under the MIT License (the "License");
14
+ * you may not use this file except in compliance with
15
+ * the License. You may obtain a copy of the License at
16
+ *
17
+ * https://opensource.org/licenses/MIT
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+ const logger_1 = __importDefault(require("@fonoster/logger"));
26
+ const service_1 = __importDefault(require("./service"));
27
+ if (!process.env.PATH_TO_AUTH) {
28
+ logger_1.default.error("environment variable PATH_TO_AUTH is required but was not found");
29
+ process.exit(1);
30
+ }
31
+ try {
32
+ const users = require(process.env.PATH_TO_AUTH);
33
+ service_1.default({ bindAddr: "", users });
34
+ }
35
+ catch (e) {
36
+ if (e.code === "MODULE_NOT_FOUND") {
37
+ logger_1.default.error(`auth file not found [path = ${process.env.PATH_TO_AUTH}]`);
38
+ }
39
+ else {
40
+ logger_1.default.error(e);
41
+ }
42
+ }
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { User } from './types';
3
+ export default function SimpleAuthProcessor(config: {
4
+ bindAddr: string;
5
+ users: User[];
6
+ }): void;
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ /*
8
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
9
+ * http://github.com/fonoster/routr
10
+ *
11
+ * This file is part of Routr
12
+ *
13
+ * Licensed under the MIT License (the "License");
14
+ * you may not use this file except in compliance with
15
+ * the License. You may obtain a copy of the License at
16
+ *
17
+ * https://opensource.org/licenses/MIT
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+ const logger_1 = __importDefault(require("@fonoster/logger"));
26
+ const common_1 = require("@routr/common");
27
+ const utils_1 = require("./utils");
28
+ const processor_1 = __importDefault(require("@routr/processor"));
29
+ function SimpleAuthProcessor(config) {
30
+ const { bindAddr, users } = config;
31
+ new processor_1.default({ bindAddr, name: "simpleauth" })
32
+ .listen((req, res) => {
33
+ logger_1.default.verbose(JSON.stringify(req, null, ' '));
34
+ // Calculate and return challenge
35
+ if (req.message.authorization) {
36
+ const auth = Object.assign({}, req.message.authorization);
37
+ auth.method = req.method;
38
+ // Calculate response and compare with the one send by the endpoint
39
+ const calcRes = common_1.calculateAuthResponse(auth, utils_1.getCredentials(auth.username, users));
40
+ if (calcRes !== auth.response) {
41
+ return res.send(utils_1.createUnauthorizedResponse(auth.realm));
42
+ }
43
+ }
44
+ else {
45
+ return res.send(utils_1.createUnauthorizedResponse(req.message.request_uri.host));
46
+ }
47
+ // Forward request to next middleware
48
+ res.send(req);
49
+ });
50
+ }
51
+ exports.default = SimpleAuthProcessor;
@@ -0,0 +1,4 @@
1
+ export interface User {
2
+ username: string;
3
+ secret: string;
4
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,23 @@
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
+ response_type: number;
9
+ www_authenticate: {
10
+ scheme: string;
11
+ realm: string;
12
+ qop: string;
13
+ opaque: string;
14
+ stale: boolean;
15
+ nonce: string;
16
+ algorithm: string;
17
+ };
18
+ extensions: {
19
+ name: string;
20
+ value: number;
21
+ }[];
22
+ };
23
+ };
package/dist/utils.js ADDED
@@ -0,0 +1,48 @@
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
+ response_type: 17,
30
+ www_authenticate: {
31
+ scheme: 'Digest',
32
+ realm: realm,
33
+ qop: params.qop,
34
+ opaque: '',
35
+ stale: false,
36
+ nonce: common_1.generateNonce(),
37
+ algorithm: params.algorithm
38
+ },
39
+ extensions: [
40
+ {
41
+ "name": "Expires",
42
+ "value": 0
43
+ }
44
+ ]
45
+ }
46
+ };
47
+ };
48
+ exports.createUnauthorizedResponse = createUnauthorizedResponse;
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@routr/simpleauth",
3
+ "version": "2.0.5-alpha.3",
4
+ "description": "This middleware delegates authentication to an external service",
5
+ "author": "Pedro Sanders <psanders@fonoster.com>",
6
+ "homepage": "https://github.com/fonoster/routr#readme",
7
+ "license": "MIT",
8
+ "main": "dist/simpleauth",
9
+ "types": "dist/simpleauth",
10
+ "directories": {
11
+ "src": "src",
12
+ "test": "test"
13
+ },
14
+ "scripts": {
15
+ "prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
16
+ "build": "tsc -b tsconfig.json"
17
+ },
18
+ "bin": {
19
+ "run_simpleauth": "dist/runner.js"
20
+ },
21
+ "dependencies": {
22
+ "@fonoster/logger": "^0.3.3",
23
+ "@routr/common": "^2.0.5-alpha.3",
24
+ "@routr/processor": "^2.0.5-alpha.3"
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/fonoster/routr.git"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/fonoster/routr/issues"
38
+ },
39
+ "gitHead": "7d942466133a03f4bcfe0dc100f1a922b3ed14ad"
40
+ }