@cryptexlabs/codex-nodejs-common 0.9.2 → 0.9.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/lib/package.json +3 -1
- package/lib/src/auth/authf-authenticator.d.ts +10 -0
- package/lib/src/auth/authf-authenticator.js +43 -0
- package/lib/src/auth/authf-authenticator.js.map +1 -0
- package/lib/src/auth/authf-authenticator.options.interface.d.ts +3 -0
- package/lib/src/auth/authf-authenticator.options.interface.js +3 -0
- package/lib/src/auth/authf-authenticator.options.interface.js.map +1 -0
- package/lib/src/auth/index.d.ts +2 -0
- package/lib/src/auth/index.js +2 -0
- package/lib/src/auth/index.js.map +1 -1
- package/package.json +3 -1
- package/src/auth/authf-authenticator.options.interface.ts +3 -0
- package/src/auth/authf-authenticator.ts +44 -0
- package/src/auth/index.ts +2 -0
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cryptexlabs/codex-nodejs-common",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Common code for Assistant applications",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"repository": "git@gitlab.com:cryptexlabs/public/codex-nodejs-common.git",
|
|
@@ -22,9 +22,11 @@
|
|
|
22
22
|
"@nestjs/platform-ws": "8.0.6",
|
|
23
23
|
"@nestjs/swagger": "5.0.9",
|
|
24
24
|
"@nestjs/websockets": "8.0.6",
|
|
25
|
+
"axios": "0.19.0",
|
|
25
26
|
"rxjs": "^7.1.0"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
29
|
+
"@cryptexlabs/authf-data-model": "^0.9.9",
|
|
28
30
|
"@types/express": "4.17.8",
|
|
29
31
|
"@types/express-serve-static-core": "4.17.24",
|
|
30
32
|
"@types/i18n": "0.12.0",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AuthenticatorInterface } from "./authenticator.interface";
|
|
2
|
+
import { ClientInterface } from "@cryptexlabs/codex-data-model";
|
|
3
|
+
import { AuthfAuthenticatorOptionsInterface } from "./authf-authenticator.options.interface";
|
|
4
|
+
export declare class AuthfAuthenticator implements AuthenticatorInterface {
|
|
5
|
+
private readonly authfUrl;
|
|
6
|
+
private readonly client;
|
|
7
|
+
private readonly options?;
|
|
8
|
+
constructor(authfUrl: string, client: ClientInterface, options?: AuthfAuthenticatorOptionsInterface);
|
|
9
|
+
authenticate(token: string): Promise<boolean>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthfAuthenticator = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const uuid_1 = require("uuid");
|
|
6
|
+
class AuthfAuthenticator {
|
|
7
|
+
constructor(authfUrl, client, options) {
|
|
8
|
+
this.authfUrl = authfUrl;
|
|
9
|
+
this.client = client;
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
async authenticate(token) {
|
|
13
|
+
var _a;
|
|
14
|
+
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.authEnabled) === false) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
const now = new Date();
|
|
18
|
+
try {
|
|
19
|
+
await axios_1.default.get(`/api/v1/authenticated`, {
|
|
20
|
+
baseURL: this.authfUrl,
|
|
21
|
+
headers: {
|
|
22
|
+
"X-Correlation-Id": uuid_1.v4(),
|
|
23
|
+
"Accept-Language": "en-US",
|
|
24
|
+
"X-Started": now.toISOString(),
|
|
25
|
+
"X-Created": now.toISOString(),
|
|
26
|
+
"X-Context-Category": "default",
|
|
27
|
+
"X-Context-Id": "none",
|
|
28
|
+
"X-Client-Name": this.client.name,
|
|
29
|
+
"X-Client-Version": this.client.version,
|
|
30
|
+
"X-Client-Variant": this.client.variant,
|
|
31
|
+
"X-Client-Id": this.client.id,
|
|
32
|
+
Authorization: `Bearer ${token}`,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.AuthfAuthenticator = AuthfAuthenticator;
|
|
43
|
+
//# sourceMappingURL=authf-authenticator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authf-authenticator.js","sourceRoot":"","sources":["../../../src/auth/authf-authenticator.ts"],"names":[],"mappings":";;;AAGA,iCAA0B;AAC1B,+BAAoC;AAEpC,MAAa,kBAAkB;IAC7B,YACmB,QAAgB,EAChB,MAAuB,EACvB,OAA4C;QAF5C,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAiB;QACvB,YAAO,GAAP,OAAO,CAAqC;IAC5D,CAAC;IAEG,KAAK,CAAC,YAAY,CAAC,KAAa;;QACrC,IAAI,OAAA,IAAI,CAAC,OAAO,0CAAE,WAAW,MAAK,KAAK,EAAE;YACvC,OAAO,IAAI,CAAC;SACb;QAED,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QAEvB,IAAI;YACF,MAAM,eAAK,CAAC,GAAG,CAAC,uBAAuB,EAAE;gBACvC,OAAO,EAAE,IAAI,CAAC,QAAQ;gBACtB,OAAO,EAAE;oBACP,kBAAkB,EAAE,SAAM,EAAE;oBAC5B,iBAAiB,EAAE,OAAO;oBAC1B,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE;oBAC9B,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE;oBAC9B,oBAAoB,EAAE,SAAS;oBAC/B,cAAc,EAAE,MAAM;oBACtB,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;oBACjC,kBAAkB,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;oBACvC,kBAAkB,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;oBACvC,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE;oBAC7B,aAAa,EAAE,UAAU,KAAK,EAAE;iBACjC;aACF,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC;SACb;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,KAAK,CAAC;SACd;IACH,CAAC;CACF;AArCD,gDAqCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authf-authenticator.options.interface.js","sourceRoot":"","sources":["../../../src/auth/authf-authenticator.options.interface.ts"],"names":[],"mappings":""}
|
package/lib/src/auth/index.d.ts
CHANGED
|
@@ -6,3 +6,5 @@ export * from "./http-authz.attach-objects.guard.util";
|
|
|
6
6
|
export * from "./http-authz.detach-objects.guard.util";
|
|
7
7
|
export * from "./http-authz.action-to-sub-objects.guard.util";
|
|
8
8
|
export * from "./http-authz.list-sub-objects.guard.util";
|
|
9
|
+
export * from "./authf-authenticator";
|
|
10
|
+
export * from "./authf-authenticator.options.interface";
|
package/lib/src/auth/index.js
CHANGED
|
@@ -18,4 +18,6 @@ __exportStar(require("./http-authz.attach-objects.guard.util"), exports);
|
|
|
18
18
|
__exportStar(require("./http-authz.detach-objects.guard.util"), exports);
|
|
19
19
|
__exportStar(require("./http-authz.action-to-sub-objects.guard.util"), exports);
|
|
20
20
|
__exportStar(require("./http-authz.list-sub-objects.guard.util"), exports);
|
|
21
|
+
__exportStar(require("./authf-authenticator"), exports);
|
|
22
|
+
__exportStar(require("./authf-authenticator.options.interface"), exports);
|
|
21
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4DAA0C;AAC1C,+DAA6C;AAC7C,uDAAqC;AACrC,0DAAwC;AACxC,yEAAuD;AACvD,yEAAuD;AACvD,gFAA8D;AAC9D,2EAAyD"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4DAA0C;AAC1C,+DAA6C;AAC7C,uDAAqC;AACrC,0DAAwC;AACxC,yEAAuD;AACvD,yEAAuD;AACvD,gFAA8D;AAC9D,2EAAyD;AACzD,wDAAsC;AACtC,0EAAwD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cryptexlabs/codex-nodejs-common",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Common code for Assistant applications",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"repository": "git@gitlab.com:cryptexlabs/public/codex-nodejs-common.git",
|
|
@@ -22,9 +22,11 @@
|
|
|
22
22
|
"@nestjs/platform-ws": "8.0.6",
|
|
23
23
|
"@nestjs/swagger": "5.0.9",
|
|
24
24
|
"@nestjs/websockets": "8.0.6",
|
|
25
|
+
"axios": "0.19.0",
|
|
25
26
|
"rxjs": "^7.1.0"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
29
|
+
"@cryptexlabs/authf-data-model": "^0.9.9",
|
|
28
30
|
"@types/express": "4.17.8",
|
|
29
31
|
"@types/express-serve-static-core": "4.17.24",
|
|
30
32
|
"@types/i18n": "0.12.0",
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AuthenticatorInterface } from "./authenticator.interface";
|
|
2
|
+
import { ClientInterface } from "@cryptexlabs/codex-data-model";
|
|
3
|
+
import { AuthfAuthenticatorOptionsInterface } from "./authf-authenticator.options.interface";
|
|
4
|
+
import axios from "axios";
|
|
5
|
+
import { v4 as uuidv4 } from "uuid";
|
|
6
|
+
|
|
7
|
+
export class AuthfAuthenticator implements AuthenticatorInterface {
|
|
8
|
+
constructor(
|
|
9
|
+
private readonly authfUrl: string,
|
|
10
|
+
private readonly client: ClientInterface,
|
|
11
|
+
private readonly options?: AuthfAuthenticatorOptionsInterface
|
|
12
|
+
) {}
|
|
13
|
+
|
|
14
|
+
public async authenticate(token: string): Promise<boolean> {
|
|
15
|
+
if (this.options?.authEnabled === false) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const now = new Date();
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
await axios.get(`/api/v1/authenticated`, {
|
|
23
|
+
baseURL: this.authfUrl,
|
|
24
|
+
headers: {
|
|
25
|
+
"X-Correlation-Id": uuidv4(),
|
|
26
|
+
"Accept-Language": "en-US",
|
|
27
|
+
"X-Started": now.toISOString(),
|
|
28
|
+
"X-Created": now.toISOString(),
|
|
29
|
+
"X-Context-Category": "default",
|
|
30
|
+
"X-Context-Id": "none",
|
|
31
|
+
"X-Client-Name": this.client.name,
|
|
32
|
+
"X-Client-Version": this.client.version,
|
|
33
|
+
"X-Client-Variant": this.client.variant,
|
|
34
|
+
"X-Client-Id": this.client.id,
|
|
35
|
+
Authorization: `Bearer ${token}`,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return true;
|
|
40
|
+
} catch (e) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/auth/index.ts
CHANGED
|
@@ -6,3 +6,5 @@ export * from "./http-authz.attach-objects.guard.util";
|
|
|
6
6
|
export * from "./http-authz.detach-objects.guard.util";
|
|
7
7
|
export * from "./http-authz.action-to-sub-objects.guard.util";
|
|
8
8
|
export * from "./http-authz.list-sub-objects.guard.util";
|
|
9
|
+
export * from "./authf-authenticator";
|
|
10
|
+
export * from "./authf-authenticator.options.interface";
|