@tstdl/base 0.82.6 → 0.82.7
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/api/client/client.js +2 -1
- package/api/client/client.js.map +1 -1
- package/api/types.d.ts +3 -3
- package/authentication/authentication.api.d.ts +98 -14
- package/authentication/authentication.api.js +31 -27
- package/authentication/authentication.api.js.map +1 -1
- package/authentication/client/api.client.d.ts +50 -0
- package/authentication/client/api.client.js +27 -0
- package/authentication/client/api.client.js.map +1 -0
- package/authentication/client/authentication.service.d.ts +39 -0
- package/authentication/client/authentication.service.js +176 -0
- package/authentication/client/authentication.service.js.map +1 -0
- package/authentication/client/index.d.ts +4 -0
- package/authentication/client/index.js +21 -0
- package/authentication/client/index.js.map +1 -0
- package/authentication/client/module.d.ts +8 -0
- package/authentication/client/module.js +16 -0
- package/authentication/client/module.js.map +1 -0
- package/authentication/client/tokens.d.ts +4 -0
- package/authentication/client/tokens.js +7 -0
- package/authentication/client/tokens.js.map +1 -0
- package/authentication/models/authentication-session.model.d.ts +0 -2
- package/authentication/models/authentication-session.model.js +0 -10
- package/authentication/models/authentication-session.model.js.map +1 -1
- package/authentication/models/index.d.ts +1 -0
- package/authentication/models/index.js +1 -0
- package/authentication/models/index.js.map +1 -1
- package/authentication/models/token-payload-base.model.d.ts +7 -0
- package/authentication/models/token-payload-base.model.js +19 -0
- package/authentication/models/token-payload-base.model.js.map +1 -1
- package/authentication/models/token.model.d.ts +16 -0
- package/authentication/models/token.model.js +3 -0
- package/authentication/models/token.model.js.map +1 -0
- package/authentication/{authentication-credentials.repository.d.ts → server/authentication-credentials.repository.d.ts} +2 -2
- package/authentication/{authentication-credentials.repository.js → server/authentication-credentials.repository.js} +1 -1
- package/authentication/server/authentication-credentials.repository.js.map +1 -0
- package/authentication/{authentication-session.repository.d.ts → server/authentication-session.repository.d.ts} +2 -3
- package/authentication/{authentication-session.repository.js → server/authentication-session.repository.js} +0 -0
- package/authentication/server/authentication-session.repository.js.map +1 -0
- package/authentication/server/authentication-token-payload.provider.d.ts +3 -0
- package/authentication/{authentication-token-payload.provider.js → server/authentication-token-payload.provider.js} +1 -1
- package/authentication/server/authentication-token-payload.provider.js.map +1 -0
- package/authentication/server/authentication.api-controller.d.ts +13 -0
- package/authentication/server/authentication.api-controller.js +65 -0
- package/authentication/server/authentication.api-controller.js.map +1 -0
- package/authentication/{authentication.service.d.ts → server/authentication.service.d.ts} +23 -11
- package/authentication/{authentication.service.js → server/authentication.service.js} +92 -47
- package/authentication/server/authentication.service.js.map +1 -0
- package/authentication/server/helper.d.ts +13 -0
- package/authentication/server/helper.js +62 -0
- package/authentication/server/helper.js.map +1 -0
- package/authentication/server/module.d.ts +12 -0
- package/authentication/server/module.js +19 -0
- package/authentication/server/module.js.map +1 -0
- package/authentication/server/mongo/index.d.ts +2 -0
- package/authentication/server/mongo/index.js +19 -0
- package/authentication/server/mongo/index.js.map +1 -0
- package/authentication/{mongo → server/mongo}/mongo-authentication-credentials.repository.d.ts +15 -18
- package/authentication/{mongo → server/mongo}/mongo-authentication-credentials.repository.js +36 -27
- package/authentication/server/mongo/mongo-authentication-credentials.repository.js.map +1 -0
- package/authentication/{mongo → server/mongo}/mongo-authentication-session.repository.d.ts +12 -15
- package/authentication/{mongo → server/mongo}/mongo-authentication-session.repository.js +27 -22
- package/authentication/server/mongo/mongo-authentication-session.repository.js.map +1 -0
- package/authentication/{tokens.d.ts → server/tokens.d.ts} +1 -1
- package/authentication/{tokens.js → server/tokens.js} +1 -1
- package/authentication/server/tokens.js.map +1 -0
- package/container/token.d.ts +2 -2
- package/container/types.d.ts +2 -1
- package/cookie/cookie.d.ts +14 -0
- package/cookie/cookie.js +58 -0
- package/cookie/cookie.js.map +1 -0
- package/cookie/index.d.ts +1 -0
- package/cookie/index.js +18 -0
- package/cookie/index.js.map +1 -0
- package/examples/api/authentication.d.ts +1 -0
- package/examples/api/authentication.js +51 -0
- package/examples/api/authentication.js.map +1 -0
- package/examples/api/basic-overview.js +4 -4
- package/examples/api/basic-overview.js.map +1 -1
- package/examples/api/custom-authentication.d.ts +1 -0
- package/examples/api/custom-authentication.js +89 -0
- package/examples/api/custom-authentication.js.map +1 -0
- package/examples/api/streaming.js +10 -8
- package/examples/api/streaming.js.map +1 -1
- package/http/cookie-parser.d.ts +1 -3
- package/http/cookie-parser.js +10 -19
- package/http/cookie-parser.js.map +1 -1
- package/http/http-headers.d.ts +2 -2
- package/http/http-headers.js +11 -11
- package/http/http-headers.js.map +1 -1
- package/http/http-value-map.js +13 -13
- package/http/http-value-map.js.map +1 -1
- package/http/server/http-server-response.d.ts +8 -3
- package/http/server/http-server-response.js +8 -0
- package/http/server/http-server-response.js.map +1 -1
- package/http/server/node/module.d.ts +2 -2
- package/http/server/node/module.js +3 -5
- package/http/server/node/module.js.map +1 -1
- package/mail/clients/nodemailer.mail-client.js +1 -1
- package/mail/clients/nodemailer.mail-client.js.map +1 -1
- package/message-bus/broadcast-channel/broadcast-channel-message-bus-provider.d.ts +1 -1
- package/message-bus/broadcast-channel/broadcast-channel-message-bus-provider.js +21 -2
- package/message-bus/broadcast-channel/broadcast-channel-message-bus-provider.js.map +1 -1
- package/message-bus/broadcast-channel/broadcast-channel-message-bus.d.ts +4 -4
- package/message-bus/broadcast-channel/broadcast-channel-message-bus.js +27 -4
- package/message-bus/broadcast-channel/broadcast-channel-message-bus.js.map +1 -1
- package/message-bus/broadcast-channel/index.d.ts +1 -0
- package/message-bus/broadcast-channel/index.js +1 -0
- package/message-bus/broadcast-channel/index.js.map +1 -1
- package/message-bus/broadcast-channel/module.d.ts +4 -0
- package/message-bus/broadcast-channel/module.js +17 -0
- package/message-bus/broadcast-channel/module.js.map +1 -0
- package/message-bus/local/index.d.ts +1 -0
- package/message-bus/local/index.js +1 -0
- package/message-bus/local/index.js.map +1 -1
- package/message-bus/local/local-message-bus-provider.d.ts +0 -5
- package/message-bus/local/local-message-bus-provider.js +1 -13
- package/message-bus/local/local-message-bus-provider.js.map +1 -1
- package/message-bus/local/local-message-bus.d.ts +1 -1
- package/message-bus/local/local-message-bus.js +2 -2
- package/message-bus/local/local-message-bus.js.map +1 -1
- package/message-bus/local/module.d.ts +4 -0
- package/message-bus/local/module.js +17 -0
- package/message-bus/local/module.js.map +1 -0
- package/message-bus/message-bus-base.d.ts +1 -1
- package/message-bus/message-bus-base.js +1 -1
- package/message-bus/message-bus-base.js.map +1 -1
- package/message-bus/message-bus.d.ts +1 -0
- package/message-bus/message-bus.js +3 -0
- package/message-bus/message-bus.js.map +1 -1
- package/notification/notification.service.js +2 -2
- package/notification/notification.service.js.map +1 -1
- package/object-storage/s3/s3.object.js +3 -3
- package/object-storage/s3/s3.object.js.map +1 -1
- package/package.json +4 -4
- package/schema/schemas/assign.js +2 -0
- package/schema/schemas/assign.js.map +1 -1
- package/schema/schemas/object.d.ts +1 -0
- package/schema/schemas/object.js +2 -1
- package/schema/schemas/object.js.map +1 -1
- package/schema/types/types.d.ts +1 -1
- package/schema/utils/schema.js.map +1 -1
- package/utils/array/array.js +2 -2
- package/utils/array/array.js.map +1 -1
- package/utils/string/index.d.ts +1 -0
- package/utils/string/index.js +1 -0
- package/utils/string/index.js.map +1 -1
- package/utils/string/title-case.d.ts +1 -0
- package/utils/string/title-case.js +13 -0
- package/utils/string/title-case.js.map +1 -0
- package/utils/type-guards.d.ts +1 -1
- package/utils/type-guards.js.map +1 -1
- package/utils/type-of.d.ts +1 -1
- package/utils/type-of.js +3 -4
- package/utils/type-of.js.map +1 -1
- package/authentication/authentication-credentials.repository.js.map +0 -1
- package/authentication/authentication-session.repository.js.map +0 -1
- package/authentication/authentication-token-payload.provider.d.ts +0 -3
- package/authentication/authentication-token-payload.provider.js.map +0 -1
- package/authentication/authentication.service.js.map +0 -1
- package/authentication/mongo/mongo-authentication-credentials.repository.js.map +0 -1
- package/authentication/mongo/mongo-authentication-session.repository.js.map +0 -1
- package/authentication/tokens.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../source/authentication/client/module.ts"],"names":[],"mappings":";;;AACA,+CAAwC;AAExC,yDAAgD;AAEhD,qCAAkF;AAOlF,SAAgB,6BAA6B,CAAC,SAA8C,EAAE;IAC5F,IAAI,IAAA,uBAAS,EAAC,MAAM,CAAC,uBAAuB,CAAC,EAAE;QAC7C,qBAAS,CAAC,iBAAiB,CAAC,kCAAyB,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,uBAAuB,EAAE,CAAC,CAAC;KACtG;IAED,IAAI,IAAA,uBAAS,EAAC,MAAM,CAAC,yBAAyB,CAAC,EAAE;QAC/C,qBAAS,CAAC,QAAQ,CAAC,oCAA2B,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,yBAAyB,EAAE,CAAC,CAAC;KACjG;AACH,CAAC;AARD,sEAQC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ApiClient } from "../../api/client";
|
|
2
|
+
import type { AuthenticationApiDefinition } from '../authentication.api';
|
|
3
|
+
export declare const AUTHENTICATION_API_CLIENT: import("../../container").InjectionToken<ApiClient<AuthenticationApiDefinition<any, any>>, any>;
|
|
4
|
+
export declare const INITIAL_AUTHENTICATION_DATA: import("../../container").InjectionToken<unknown, any>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.INITIAL_AUTHENTICATION_DATA = exports.AUTHENTICATION_API_CLIENT = void 0;
|
|
4
|
+
const container_1 = require("../../container");
|
|
5
|
+
exports.AUTHENTICATION_API_CLIENT = (0, container_1.injectionToken)('AUTHENTICATION_API_CLIENT');
|
|
6
|
+
exports.INITIAL_AUTHENTICATION_DATA = (0, container_1.injectionToken)('INITIAL_AUTHENTICATION_DATA');
|
|
7
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../../source/authentication/client/tokens.ts"],"names":[],"mappings":";;;AACA,+CAA6C;AAGhC,QAAA,yBAAyB,GAAG,IAAA,0BAAc,EAAmD,2BAA2B,CAAC,CAAC;AAE1H,QAAA,2BAA2B,GAAG,IAAA,0BAAc,EAAC,6BAA6B,CAAC,CAAC"}
|
|
@@ -5,7 +5,6 @@ export declare class AuthenticationSession {
|
|
|
5
5
|
begin: number;
|
|
6
6
|
/** timestamp */
|
|
7
7
|
end: number;
|
|
8
|
-
tokenId: string;
|
|
9
8
|
refreshTokenHashVersion: number;
|
|
10
9
|
refreshTokenSalt: Uint8Array;
|
|
11
10
|
refreshTokenHash: Uint8Array;
|
|
@@ -14,7 +13,6 @@ export declare class NewAuthenticationSession {
|
|
|
14
13
|
subject: string;
|
|
15
14
|
begin: number;
|
|
16
15
|
end: number;
|
|
17
|
-
tokenId: string;
|
|
18
16
|
refreshTokenHashVersion: number;
|
|
19
17
|
refreshTokenSalt: Uint8Array;
|
|
20
18
|
refreshTokenHash: Uint8Array;
|
|
@@ -18,7 +18,6 @@ class AuthenticationSession {
|
|
|
18
18
|
begin;
|
|
19
19
|
/** timestamp */
|
|
20
20
|
end;
|
|
21
|
-
tokenId;
|
|
22
21
|
refreshTokenHashVersion;
|
|
23
22
|
refreshTokenSalt;
|
|
24
23
|
refreshTokenHash;
|
|
@@ -39,10 +38,6 @@ __decorate([
|
|
|
39
38
|
(0, schema_1.Property)(),
|
|
40
39
|
__metadata("design:type", Number)
|
|
41
40
|
], AuthenticationSession.prototype, "end", void 0);
|
|
42
|
-
__decorate([
|
|
43
|
-
(0, schema_1.Property)(),
|
|
44
|
-
__metadata("design:type", String)
|
|
45
|
-
], AuthenticationSession.prototype, "tokenId", void 0);
|
|
46
41
|
__decorate([
|
|
47
42
|
(0, schema_1.Property)(),
|
|
48
43
|
__metadata("design:type", Number)
|
|
@@ -60,7 +55,6 @@ class NewAuthenticationSession {
|
|
|
60
55
|
subject;
|
|
61
56
|
begin;
|
|
62
57
|
end;
|
|
63
|
-
tokenId;
|
|
64
58
|
refreshTokenHashVersion;
|
|
65
59
|
refreshTokenSalt;
|
|
66
60
|
refreshTokenHash;
|
|
@@ -77,10 +71,6 @@ __decorate([
|
|
|
77
71
|
(0, schema_1.Property)(),
|
|
78
72
|
__metadata("design:type", Number)
|
|
79
73
|
], NewAuthenticationSession.prototype, "end", void 0);
|
|
80
|
-
__decorate([
|
|
81
|
-
(0, schema_1.Property)(),
|
|
82
|
-
__metadata("design:type", String)
|
|
83
|
-
], NewAuthenticationSession.prototype, "tokenId", void 0);
|
|
84
74
|
__decorate([
|
|
85
75
|
(0, schema_1.Property)(),
|
|
86
76
|
__metadata("design:type", Number)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication-session.model.js","sourceRoot":"","sources":["../../../source/authentication/models/authentication-session.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAoC;AAEpC,MAAa,qBAAqB;IAEhC,EAAE,CAAS;IAGX,OAAO,CAAS;IAEhB,gBAAgB;IAEhB,KAAK,CAAS;IAEd,gBAAgB;IAEhB,GAAG,CAAS;IAGZ,
|
|
1
|
+
{"version":3,"file":"authentication-session.model.js","sourceRoot":"","sources":["../../../source/authentication/models/authentication-session.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAoC;AAEpC,MAAa,qBAAqB;IAEhC,EAAE,CAAS;IAGX,OAAO,CAAS;IAEhB,gBAAgB;IAEhB,KAAK,CAAS;IAEd,gBAAgB;IAEhB,GAAG,CAAS;IAGZ,uBAAuB,CAAS;IAGhC,gBAAgB,CAAa;IAG7B,gBAAgB,CAAa;CAC9B;AAtBC;IAAC,IAAA,iBAAQ,GAAE;;iDACA;AAEX;IAAC,IAAA,iBAAQ,GAAE;;sDACK;AAGhB;IAAC,IAAA,iBAAQ,GAAE;;oDACG;AAGd;IAAC,IAAA,iBAAQ,GAAE;;kDACC;AAEZ;IAAC,IAAA,iBAAQ,GAAE;;sEACqB;AAEhC;IAAC,IAAA,iBAAQ,GAAE;8BACO,UAAU;+DAAC;AAE7B;IAAC,IAAA,iBAAQ,GAAE;8BACO,UAAU;+DAAC;AAtB/B,sDAuBC;AAED,MAAa,wBAAwB;IAEnC,OAAO,CAAS;IAGhB,KAAK,CAAS;IAGd,GAAG,CAAS;IAGZ,uBAAuB,CAAS;IAGhC,gBAAgB,CAAa;IAG7B,gBAAgB,CAAa;CAC9B;AAjBC;IAAC,IAAA,iBAAQ,GAAE;;yDACK;AAEhB;IAAC,IAAA,iBAAQ,GAAE;;uDACG;AAEd;IAAC,IAAA,iBAAQ,GAAE;;qDACC;AAEZ;IAAC,IAAA,iBAAQ,GAAE;;yEACqB;AAEhC;IAAC,IAAA,iBAAQ,GAAE;8BACO,UAAU;kEAAC;AAE7B;IAAC,IAAA,iBAAQ,GAAE;8BACO,UAAU;kEAAC;AAjB/B,4DAkBC"}
|
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./authentication-credentials.model"), exports);
|
|
18
18
|
__exportStar(require("./authentication-session.model"), exports);
|
|
19
19
|
__exportStar(require("./token-payload-base.model"), exports);
|
|
20
|
+
__exportStar(require("./token.model"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/authentication/models/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qEAAmD;AACnD,iEAA+C;AAC/C,6DAA2C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/authentication/models/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qEAAmD;AACnD,iEAA+C;AAC/C,6DAA2C;AAC3C,gDAA8B"}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
export declare class TokenPayloadBase {
|
|
2
|
+
/** token id */
|
|
2
3
|
jti: string;
|
|
4
|
+
/** issue timestamp in seconds */
|
|
3
5
|
iat: number;
|
|
6
|
+
/** expiration timestamp in seconds */
|
|
4
7
|
exp: number;
|
|
8
|
+
/** refresh token expiration timestamp in seconds */
|
|
9
|
+
refreshTokenExp: number;
|
|
10
|
+
sessionId: string;
|
|
11
|
+
subject: string;
|
|
5
12
|
}
|
|
@@ -12,9 +12,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.TokenPayloadBase = void 0;
|
|
13
13
|
const property_1 = require("../../schema/decorators/property");
|
|
14
14
|
class TokenPayloadBase {
|
|
15
|
+
/** token id */
|
|
15
16
|
jti;
|
|
17
|
+
/** issue timestamp in seconds */
|
|
16
18
|
iat;
|
|
19
|
+
/** expiration timestamp in seconds */
|
|
17
20
|
exp;
|
|
21
|
+
/** refresh token expiration timestamp in seconds */
|
|
22
|
+
refreshTokenExp;
|
|
23
|
+
sessionId;
|
|
24
|
+
subject;
|
|
18
25
|
}
|
|
19
26
|
__decorate([
|
|
20
27
|
(0, property_1.Property)(),
|
|
@@ -28,5 +35,17 @@ __decorate([
|
|
|
28
35
|
(0, property_1.Property)(),
|
|
29
36
|
__metadata("design:type", Number)
|
|
30
37
|
], TokenPayloadBase.prototype, "exp", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, property_1.Property)(),
|
|
40
|
+
__metadata("design:type", Number)
|
|
41
|
+
], TokenPayloadBase.prototype, "refreshTokenExp", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, property_1.Property)(),
|
|
44
|
+
__metadata("design:type", String)
|
|
45
|
+
], TokenPayloadBase.prototype, "sessionId", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, property_1.Property)(),
|
|
48
|
+
__metadata("design:type", String)
|
|
49
|
+
], TokenPayloadBase.prototype, "subject", void 0);
|
|
31
50
|
exports.TokenPayloadBase = TokenPayloadBase;
|
|
32
51
|
//# sourceMappingURL=token-payload-base.model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-payload-base.model.js","sourceRoot":"","sources":["../../../source/authentication/models/token-payload-base.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+DAAwD;AAExD,MAAa,gBAAgB;
|
|
1
|
+
{"version":3,"file":"token-payload-base.model.js","sourceRoot":"","sources":["../../../source/authentication/models/token-payload-base.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+DAAwD;AAExD,MAAa,gBAAgB;IAC3B,eAAe;IAEf,GAAG,CAAS;IAEZ,iCAAiC;IAEjC,GAAG,CAAS;IAEZ,sCAAsC;IAEtC,GAAG,CAAS;IAEZ,oDAAoD;IAEpD,eAAe,CAAS;IAGxB,SAAS,CAAS;IAGlB,OAAO,CAAS;CACjB;AApBC;IAAC,IAAA,mBAAQ,GAAE;;6CACC;AAGZ;IAAC,IAAA,mBAAQ,GAAE;;6CACC;AAGZ;IAAC,IAAA,mBAAQ,GAAE;;6CACC;AAGZ;IAAC,IAAA,mBAAQ,GAAE;;yDACa;AAExB;IAAC,IAAA,mBAAQ,GAAE;;mDACO;AAElB;IAAC,IAAA,mBAAQ,GAAE;;iDACK;AArBlB,4CAsBC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Record } from "../../types";
|
|
2
|
+
import type { JwtToken, JwtTokenHeader } from "../../utils/jwt";
|
|
3
|
+
import type { TokenPayloadBase } from '../models';
|
|
4
|
+
export type TokenHeader = {
|
|
5
|
+
v: number;
|
|
6
|
+
};
|
|
7
|
+
export type Token<AdditionalTokenPayload = Record<never>> = JwtToken<AdditionalTokenPayload & TokenPayloadBase, JwtTokenHeader<TokenHeader>>;
|
|
8
|
+
export type TokenPayload<T> = T & TokenPayloadBase;
|
|
9
|
+
export type RefreshTokenPayload = {
|
|
10
|
+
/** expiration timestamp in seconds */
|
|
11
|
+
exp: number;
|
|
12
|
+
subject: string;
|
|
13
|
+
sessionId: string;
|
|
14
|
+
secret: string;
|
|
15
|
+
};
|
|
16
|
+
export type RefreshToken = JwtToken<RefreshTokenPayload>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.model.js","sourceRoot":"","sources":["../../../source/authentication/models/token.model.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AuthenticationCredentials, NewAuthenticationCredentials } from '
|
|
1
|
+
import type { AuthenticationCredentials, NewAuthenticationCredentials } from '../models';
|
|
2
2
|
export declare abstract class AuthenticationCredentialsRepository {
|
|
3
|
-
abstract
|
|
3
|
+
abstract tryLoadBySubject(subject: string): Promise<AuthenticationCredentials | undefined>;
|
|
4
4
|
abstract save(credentials: NewAuthenticationCredentials | AuthenticationCredentials): Promise<void>;
|
|
5
5
|
}
|
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.AuthenticationCredentialsRepository = void 0;
|
|
10
|
-
const reflection_1 = require("
|
|
10
|
+
const reflection_1 = require("../../reflection");
|
|
11
11
|
let AuthenticationCredentialsRepository = class AuthenticationCredentialsRepository {
|
|
12
12
|
};
|
|
13
13
|
AuthenticationCredentialsRepository = __decorate([
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication-credentials.repository.js","sourceRoot":"","sources":["../../../source/authentication/server/authentication-credentials.repository.ts"],"names":[],"mappings":";;;;;;;;;AAAA,iDAAqC;AAI9B,IAAe,mCAAmC,GAAlD,MAAe,mCAAmC;CAGxD,CAAA;AAHqB,mCAAmC;IADxD,IAAA,kBAAK,GAAE;GACc,mCAAmC,CAGxD;AAHqB,kFAAmC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { NewEntity } from "
|
|
2
|
-
import type { AuthenticationSession } from '
|
|
1
|
+
import type { NewEntity } from "../../database";
|
|
2
|
+
import type { AuthenticationSession } from '../models';
|
|
3
3
|
export type AuthenticationSessionExtendData = {
|
|
4
4
|
end: number;
|
|
5
|
-
tokenId: string;
|
|
6
5
|
refreshTokenHashVersion: number;
|
|
7
6
|
refreshTokenSalt: Uint8Array;
|
|
8
7
|
refreshTokenHash: Uint8Array;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication-session.repository.js","sourceRoot":"","sources":["../../../source/authentication/server/authentication-session.repository.ts"],"names":[],"mappings":";;;AAUA,MAAsB,+BAA+B;CAQpD;AARD,0EAQC"}
|
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.AuthenticationTokenPayloadProvider = void 0;
|
|
10
|
-
const reflection_1 = require("
|
|
10
|
+
const reflection_1 = require("../../reflection");
|
|
11
11
|
let AuthenticationTokenPayloadProvider = class AuthenticationTokenPayloadProvider {
|
|
12
12
|
};
|
|
13
13
|
AuthenticationTokenPayloadProvider = __decorate([
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication-token-payload.provider.js","sourceRoot":"","sources":["../../../source/authentication/server/authentication-token-payload.provider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,iDAAqC;AAG9B,IAAe,kCAAkC,GAAjD,MAAe,kCAAkC;CAEvD,CAAA;AAFqB,kCAAkC;IADvD,IAAA,kBAAK,GAAE;GACc,kCAAkC,CAEvD;AAFqB,gFAAkC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ApiController, ApiRequestData, ApiServerResult } from "../../api/types";
|
|
2
|
+
import type { AuthenticationApiDefinition } from '../authentication.api';
|
|
3
|
+
import type { TokenPayloadBase } from '../models';
|
|
4
|
+
import { AuthenticationService } from './authentication.service';
|
|
5
|
+
export declare class AuthenticationApiController<TokenPayload extends TokenPayloadBase, AuthenticationData> implements ApiController<AuthenticationApiDefinition<TokenPayload, AuthenticationData>> {
|
|
6
|
+
readonly authenticationService: AuthenticationService<TokenPayload, AuthenticationData>;
|
|
7
|
+
constructor(authenticationService: AuthenticationService<TokenPayload, AuthenticationData>);
|
|
8
|
+
token({ parameters }: ApiRequestData<AuthenticationApiDefinition<TokenPayload, AuthenticationData>, 'token'>): Promise<ApiServerResult<AuthenticationApiDefinition<TokenPayload, AuthenticationData>, 'token'>>;
|
|
9
|
+
refresh({ request, parameters }: ApiRequestData<AuthenticationApiDefinition<TokenPayload, AuthenticationData>, 'refresh'>): Promise<ApiServerResult<AuthenticationApiDefinition<TokenPayload, AuthenticationData>, 'refresh'>>;
|
|
10
|
+
endSession({ request }: ApiRequestData<AuthenticationApiDefinition<TokenPayload, AuthenticationData>, 'endSession'>): Promise<ApiServerResult<AuthenticationApiDefinition<TokenPayload, AuthenticationData>, 'endSession'>>;
|
|
11
|
+
timestamp(): ApiServerResult<AuthenticationApiDefinition<TokenPayload, AuthenticationData>, 'timestamp'>;
|
|
12
|
+
private getAuthenticationResponse;
|
|
13
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuthenticationApiController = void 0;
|
|
13
|
+
const server_1 = require("../../api/server");
|
|
14
|
+
const unauthorized_error_1 = require("../../error/unauthorized.error");
|
|
15
|
+
const server_2 = require("../../http/server");
|
|
16
|
+
const date_time_1 = require("../../utils/date-time");
|
|
17
|
+
const authentication_api_1 = require("../authentication.api");
|
|
18
|
+
const authentication_service_1 = require("./authentication.service");
|
|
19
|
+
const helper_1 = require("./helper");
|
|
20
|
+
let AuthenticationApiController = class AuthenticationApiController {
|
|
21
|
+
authenticationService;
|
|
22
|
+
constructor(authenticationService) {
|
|
23
|
+
this.authenticationService = authenticationService;
|
|
24
|
+
}
|
|
25
|
+
async token({ parameters }) {
|
|
26
|
+
const authenticationResult = await this.authenticationService.authenticate(parameters.subject, parameters.secret);
|
|
27
|
+
if (!authenticationResult.success) {
|
|
28
|
+
throw new unauthorized_error_1.UnauthorizedError('Invalid credentials.');
|
|
29
|
+
}
|
|
30
|
+
const result = await this.authenticationService.getToken(authenticationResult.subject, parameters.data);
|
|
31
|
+
return this.getAuthenticationResponse(result);
|
|
32
|
+
}
|
|
33
|
+
async refresh({ request, parameters }) {
|
|
34
|
+
const tokenString = (0, helper_1.tryGetAuthorizationTokenStringFromRequest)(request, 'refreshToken') ?? '';
|
|
35
|
+
const result = await this.authenticationService.refresh(tokenString, parameters.data);
|
|
36
|
+
return this.getAuthenticationResponse(result);
|
|
37
|
+
}
|
|
38
|
+
async endSession({ request }) {
|
|
39
|
+
const tokenString = (0, helper_1.tryGetAuthorizationTokenStringFromRequest)(request) ?? '';
|
|
40
|
+
const token = await this.authenticationService.validateToken(tokenString);
|
|
41
|
+
await this.authenticationService.endSession(token.payload.sessionId);
|
|
42
|
+
return 'ok';
|
|
43
|
+
}
|
|
44
|
+
timestamp() {
|
|
45
|
+
return (0, date_time_1.currentTimestamp)();
|
|
46
|
+
}
|
|
47
|
+
getAuthenticationResponse({ token, jsonToken, refreshToken }) {
|
|
48
|
+
const result = jsonToken.payload;
|
|
49
|
+
return new server_2.HttpServerResponse({
|
|
50
|
+
cookies: {
|
|
51
|
+
authorization: { value: `Bearer ${token}`, httpOnly: true, secure: true, sameSite: 'strict', expires: jsonToken.payload.refreshTokenExp * 1000 },
|
|
52
|
+
refreshToken: { value: `Bearer ${refreshToken}`, httpOnly: true, secure: true, sameSite: 'strict', expires: jsonToken.payload.refreshTokenExp * 1000 }
|
|
53
|
+
},
|
|
54
|
+
body: {
|
|
55
|
+
json: result
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
AuthenticationApiController = __decorate([
|
|
61
|
+
(0, server_1.apiController)(authentication_api_1.authenticationApiDefinition),
|
|
62
|
+
__metadata("design:paramtypes", [authentication_service_1.AuthenticationService])
|
|
63
|
+
], AuthenticationApiController);
|
|
64
|
+
exports.AuthenticationApiController = AuthenticationApiController;
|
|
65
|
+
//# sourceMappingURL=authentication.api-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication.api-controller.js","sourceRoot":"","sources":["../../../source/authentication/server/authentication.api-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA6C;AAE7C,uEAA+D;AAC/D,8CAAmD;AACnD,qDAAqD;AAErD,8DAAoE;AAGpE,qEAAiE;AACjE,qCAAqE;AAG9D,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IAC7B,qBAAqB,CAA0D;IAExF,YAAY,qBAA8E;QACxF,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,EAAE,UAAU,EAA0F;QAChH,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;QAElH,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE;YACjC,MAAM,IAAI,sCAAiB,CAAC,sBAAsB,CAAC,CAAC;SACrD;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,oBAAoB,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;QAExG,OAAO,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAA4F;QAC7H,MAAM,WAAW,GAAG,IAAA,kDAAyC,EAAC,OAAO,EAAE,cAAc,CAAC,IAAI,EAAE,CAAC;QAC7F,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;QAEtF,OAAO,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAE,OAAO,EAA+F;QACvH,MAAM,WAAW,GAAG,IAAA,kDAAyC,EAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAC7E,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QAC1E,MAAM,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAErE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS;QACP,OAAO,IAAA,4BAAgB,GAAE,CAAC;IAC5B,CAAC;IAEO,yBAAyB,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAA6B;QAC7F,MAAM,MAAM,GAA4F,SAAS,CAAC,OAAO,CAAC;QAE1H,OAAO,IAAI,2BAAkB,CAAC;YAC5B,OAAO,EAAE;gBACP,aAAa,EAAE,EAAE,KAAK,EAAE,UAAU,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,eAAe,GAAG,IAAI,EAAE;gBAChJ,YAAY,EAAE,EAAE,KAAK,EAAE,UAAU,YAAY,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,eAAe,GAAG,IAAI,EAAE;aACvJ;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,MAAM;aACb;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAnDY,2BAA2B;IADvC,IAAA,sBAAa,EAAC,gDAA2B,CAAC;qCAIN,8CAAqB;GAH7C,2BAA2B,CAmDvC;AAnDY,kEAA2B"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AfterResolve } from "../../container";
|
|
2
|
+
import { afterResolve } from "../../container";
|
|
3
|
+
import type { Record } from "../../types";
|
|
4
|
+
import type { RefreshToken, Token } from '../models';
|
|
2
5
|
import { AuthenticationCredentialsRepository } from './authentication-credentials.repository';
|
|
3
6
|
import { AuthenticationSessionRepository } from './authentication-session.repository';
|
|
4
7
|
import { AuthenticationTokenPayloadProvider } from './authentication-token-payload.provider';
|
|
5
|
-
import type { TokenPayloadBase } from './models';
|
|
6
|
-
export type Token<AdditionalTokenPayload> = JwtToken<AdditionalTokenPayload & TokenPayloadBase, JwtTokenHeader<TokenHeader>>;
|
|
7
|
-
export type TokenHeader = {
|
|
8
|
-
v: number;
|
|
9
|
-
};
|
|
10
8
|
export type AuthenticationServiceOptions = {
|
|
11
|
-
/** Secret used for signing tokens */
|
|
9
|
+
/** Secret used for signing tokens and refreshTokens */
|
|
12
10
|
secret: string;
|
|
13
11
|
/** Token version, forces refresh on mismatch (useful if payload changes) */
|
|
14
12
|
version?: number;
|
|
@@ -18,10 +16,18 @@ export type AuthenticationServiceOptions = {
|
|
|
18
16
|
sessionTimeToLive?: number;
|
|
19
17
|
};
|
|
20
18
|
export type AuthenticationResult = {
|
|
19
|
+
success: true;
|
|
20
|
+
subject: string;
|
|
21
|
+
} | {
|
|
22
|
+
success: false;
|
|
23
|
+
subject?: undefined;
|
|
24
|
+
};
|
|
25
|
+
export type TokenResult<AdditionalTokenPayload = Record<never>> = {
|
|
21
26
|
token: string;
|
|
27
|
+
jsonToken: Token<AdditionalTokenPayload>;
|
|
22
28
|
refreshToken: string;
|
|
23
29
|
};
|
|
24
|
-
export declare class AuthenticationService<AdditionalTokenPayload
|
|
30
|
+
export declare class AuthenticationService<AdditionalTokenPayload = Record<never>, AdditionalAuthenticationData = Record<never>> implements AfterResolve {
|
|
25
31
|
private readonly credentialsRepository;
|
|
26
32
|
private readonly sessionRepository;
|
|
27
33
|
private readonly tokenPayloadProviderService;
|
|
@@ -29,14 +35,20 @@ export declare class AuthenticationService<AdditionalTokenPayload, AdditionalAut
|
|
|
29
35
|
private readonly tokenVersion;
|
|
30
36
|
private readonly tokenTimeToLive;
|
|
31
37
|
private readonly sessionTimeToLive;
|
|
38
|
+
private derivedTokenSigningSecret;
|
|
39
|
+
private derivedRefreshTokenSigningSecret;
|
|
32
40
|
constructor(credentialsService: AuthenticationCredentialsRepository, sessionRepository: AuthenticationSessionRepository, tokenPayloadProviderService: AuthenticationTokenPayloadProvider<AdditionalTokenPayload, AdditionalAuthenticationData>, options: AuthenticationServiceOptions);
|
|
41
|
+
[afterResolve](): Promise<void>;
|
|
42
|
+
initialize(): Promise<void>;
|
|
33
43
|
setCredentials(subject: string, secret: string): Promise<void>;
|
|
34
|
-
authenticate(subject: string, secret: string): Promise<
|
|
35
|
-
getToken(subject: string,
|
|
44
|
+
authenticate(subject: string, secret: string): Promise<AuthenticationResult>;
|
|
45
|
+
getToken(subject: string, additionalAuthenticationData: AdditionalAuthenticationData): Promise<TokenResult<AdditionalTokenPayload>>;
|
|
36
46
|
endSession(sessionId: string): Promise<void>;
|
|
37
|
-
refresh(
|
|
47
|
+
refresh(refreshToken: string, additionalAuthenticationData: AdditionalAuthenticationData): Promise<TokenResult<AdditionalTokenPayload>>;
|
|
38
48
|
validateToken(token: string): Promise<Token<AdditionalTokenPayload>>;
|
|
49
|
+
validateRefreshToken(token: string): Promise<RefreshToken>;
|
|
39
50
|
private createToken;
|
|
40
51
|
private createRefreshToken;
|
|
52
|
+
private deriveSigningSecrets;
|
|
41
53
|
private getHash;
|
|
42
54
|
}
|
|
@@ -13,21 +13,22 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.AuthenticationService = void 0;
|
|
16
|
-
const container_1 = require("
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const units_1 = require("../utils/units");
|
|
16
|
+
const container_1 = require("../../container");
|
|
17
|
+
const invalid_token_error_1 = require("../../error/invalid-token.error");
|
|
18
|
+
const alphabet_1 = require("../../utils/alphabet");
|
|
19
|
+
const cryptography_1 = require("../../utils/cryptography");
|
|
20
|
+
const date_time_1 = require("../../utils/date-time");
|
|
21
|
+
const equals_1 = require("../../utils/equals");
|
|
22
|
+
const jwt_1 = require("../../utils/jwt");
|
|
23
|
+
const random_1 = require("../../utils/random");
|
|
24
|
+
const type_guards_1 = require("../../utils/type-guards");
|
|
25
|
+
const units_1 = require("../../utils/units");
|
|
27
26
|
const authentication_credentials_repository_1 = require("./authentication-credentials.repository");
|
|
28
27
|
const authentication_session_repository_1 = require("./authentication-session.repository");
|
|
29
28
|
const authentication_token_payload_provider_1 = require("./authentication-token-payload.provider");
|
|
29
|
+
const helper_1 = require("./helper");
|
|
30
30
|
const tokens_1 = require("./tokens");
|
|
31
|
+
const SIGNING_SECRETS_LENGTH = 512;
|
|
31
32
|
let AuthenticationService = class AuthenticationService {
|
|
32
33
|
credentialsRepository;
|
|
33
34
|
sessionRepository;
|
|
@@ -36,6 +37,8 @@ let AuthenticationService = class AuthenticationService {
|
|
|
36
37
|
tokenVersion;
|
|
37
38
|
tokenTimeToLive;
|
|
38
39
|
sessionTimeToLive;
|
|
40
|
+
derivedTokenSigningSecret;
|
|
41
|
+
derivedRefreshTokenSigningSecret;
|
|
39
42
|
constructor(credentialsService, sessionRepository, tokenPayloadProviderService, options) {
|
|
40
43
|
this.credentialsRepository = credentialsService;
|
|
41
44
|
this.sessionRepository = sessionRepository;
|
|
@@ -45,6 +48,12 @@ let AuthenticationService = class AuthenticationService {
|
|
|
45
48
|
this.tokenTimeToLive = options.tokenTimeToLive ?? (5 * units_1.millisecondsPerMinute);
|
|
46
49
|
this.sessionTimeToLive = options.sessionTimeToLive ?? (5 * units_1.millisecondsPerDay);
|
|
47
50
|
}
|
|
51
|
+
async [container_1.afterResolve]() {
|
|
52
|
+
await this.initialize();
|
|
53
|
+
}
|
|
54
|
+
async initialize() {
|
|
55
|
+
await this.deriveSigningSecrets();
|
|
56
|
+
}
|
|
48
57
|
async setCredentials(subject, secret) {
|
|
49
58
|
const salt = (0, random_1.getRandomBytes)(32);
|
|
50
59
|
const hash = await this.getHash(secret, salt);
|
|
@@ -57,67 +66,78 @@ let AuthenticationService = class AuthenticationService {
|
|
|
57
66
|
await this.credentialsRepository.save(credentials);
|
|
58
67
|
}
|
|
59
68
|
async authenticate(subject, secret) {
|
|
60
|
-
const credentials = await this.credentialsRepository.
|
|
69
|
+
const credentials = await this.credentialsRepository.tryLoadBySubject(subject);
|
|
61
70
|
if ((0, type_guards_1.isUndefined)(credentials)) {
|
|
62
|
-
return false;
|
|
71
|
+
return { success: false };
|
|
63
72
|
}
|
|
64
73
|
const hash = await this.getHash(secret, credentials.salt);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const isAuthenticated = await this.authenticate(subject, secret);
|
|
69
|
-
if (!isAuthenticated) {
|
|
70
|
-
throw new error_1.UnauthorizedError('Invalid credentials.');
|
|
74
|
+
const valid = (0, equals_1.binaryEquals)(hash, credentials.hash);
|
|
75
|
+
if (valid) {
|
|
76
|
+
return { success: true, subject: credentials.subject };
|
|
71
77
|
}
|
|
78
|
+
return { success: false };
|
|
79
|
+
}
|
|
80
|
+
async getToken(subject, additionalAuthenticationData) {
|
|
72
81
|
const now = (0, date_time_1.currentTimestamp)();
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const refreshToken = await this.createRefreshToken();
|
|
76
|
-
await this.sessionRepository.insert({
|
|
82
|
+
const end = now + this.sessionTimeToLive;
|
|
83
|
+
const session = await this.sessionRepository.insert({
|
|
77
84
|
subject,
|
|
78
85
|
begin: now,
|
|
79
|
-
end
|
|
80
|
-
|
|
86
|
+
end,
|
|
87
|
+
refreshTokenHashVersion: 0,
|
|
88
|
+
refreshTokenSalt: new Uint8Array(),
|
|
89
|
+
refreshTokenHash: new Uint8Array()
|
|
90
|
+
});
|
|
91
|
+
const tokenPayload = await this.tokenPayloadProviderService?.getTokenPayload(subject, additionalAuthenticationData);
|
|
92
|
+
const { token, jsonToken } = await this.createToken(tokenPayload, subject, session.id, end, now);
|
|
93
|
+
const refreshToken = await this.createRefreshToken(subject, session.id, end);
|
|
94
|
+
await this.sessionRepository.extend(session.id, {
|
|
95
|
+
end,
|
|
81
96
|
refreshTokenHashVersion: 1,
|
|
82
97
|
refreshTokenSalt: refreshToken.salt,
|
|
83
98
|
refreshTokenHash: refreshToken.hash
|
|
84
99
|
});
|
|
85
|
-
return { token, refreshToken: refreshToken.token };
|
|
100
|
+
return { token, jsonToken, refreshToken: refreshToken.token };
|
|
86
101
|
}
|
|
87
102
|
async endSession(sessionId) {
|
|
88
103
|
const now = (0, date_time_1.currentTimestamp)();
|
|
89
104
|
await this.sessionRepository.end(sessionId, now);
|
|
90
105
|
}
|
|
91
|
-
async refresh(
|
|
106
|
+
async refresh(refreshToken, additionalAuthenticationData) {
|
|
107
|
+
const validatedToken = await this.validateRefreshToken(refreshToken);
|
|
108
|
+
const sessionId = validatedToken.payload.sessionId;
|
|
92
109
|
const session = await this.sessionRepository.load(sessionId);
|
|
93
|
-
const hash = await this.getHash(
|
|
110
|
+
const hash = await this.getHash(validatedToken.payload.secret, session.refreshTokenSalt);
|
|
94
111
|
if (session.end <= (0, date_time_1.currentTimestamp)()) {
|
|
95
|
-
throw new
|
|
112
|
+
throw new invalid_token_error_1.InvalidTokenError('Session is expired.');
|
|
96
113
|
}
|
|
97
114
|
if (!(0, equals_1.binaryEquals)(hash, session.refreshTokenHash)) {
|
|
98
|
-
throw new
|
|
115
|
+
throw new invalid_token_error_1.InvalidTokenError('Invalid refresh token.');
|
|
99
116
|
}
|
|
100
117
|
const now = (0, date_time_1.currentTimestamp)();
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
const
|
|
118
|
+
const newEnd = now + this.sessionTimeToLive;
|
|
119
|
+
const tokenPayload = await this.tokenPayloadProviderService?.getTokenPayload(session.subject, additionalAuthenticationData);
|
|
120
|
+
const { token, jsonToken } = await this.createToken(tokenPayload, session.subject, sessionId, newEnd, now);
|
|
121
|
+
const newRefreshToken = await this.createRefreshToken(validatedToken.payload.subject, sessionId, newEnd);
|
|
104
122
|
await this.sessionRepository.extend(sessionId, {
|
|
105
|
-
end:
|
|
106
|
-
tokenId: payload.jti,
|
|
123
|
+
end: newEnd,
|
|
107
124
|
refreshTokenHashVersion: 1,
|
|
108
125
|
refreshTokenSalt: newRefreshToken.salt,
|
|
109
126
|
refreshTokenHash: newRefreshToken.hash
|
|
110
127
|
});
|
|
111
|
-
return { token, refreshToken: newRefreshToken.token };
|
|
128
|
+
return { token, jsonToken, refreshToken: newRefreshToken.token };
|
|
112
129
|
}
|
|
113
130
|
async validateToken(token) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
131
|
+
return (0, helper_1.getTokenFromString)(token, this.tokenVersion, this.derivedTokenSigningSecret);
|
|
132
|
+
}
|
|
133
|
+
async validateRefreshToken(token) {
|
|
134
|
+
const validatedToken = await (0, jwt_1.parseAndValidateJwtTokenString)(token, 'HS256', this.derivedRefreshTokenSigningSecret);
|
|
135
|
+
if (validatedToken.payload.exp <= (0, date_time_1.currentTimestampSeconds)()) {
|
|
136
|
+
throw new invalid_token_error_1.InvalidTokenError('Token expired.');
|
|
117
137
|
}
|
|
118
138
|
return validatedToken;
|
|
119
139
|
}
|
|
120
|
-
async createToken(additionalTokenPayload,
|
|
140
|
+
async createToken(additionalTokenPayload, subject, sessionId, refreshTokenExpiration, timestamp) {
|
|
121
141
|
const header = {
|
|
122
142
|
v: this.tokenVersion,
|
|
123
143
|
alg: 'HS256',
|
|
@@ -127,19 +147,43 @@ let AuthenticationService = class AuthenticationService {
|
|
|
127
147
|
jti: (0, random_1.getRandomString)(24, alphabet_1.Alphabet.LowerUpperCaseNumbers),
|
|
128
148
|
iat: (0, date_time_1.timestampToTimestampSeconds)(timestamp),
|
|
129
149
|
exp: (0, date_time_1.timestampToTimestampSeconds)(timestamp + this.tokenTimeToLive),
|
|
150
|
+
refreshTokenExp: (0, date_time_1.timestampToTimestampSeconds)(refreshTokenExpiration),
|
|
151
|
+
sessionId,
|
|
152
|
+
subject,
|
|
130
153
|
...additionalTokenPayload
|
|
131
154
|
};
|
|
132
|
-
const
|
|
155
|
+
const jsonToken = {
|
|
133
156
|
header,
|
|
134
157
|
payload
|
|
135
|
-
}
|
|
136
|
-
|
|
158
|
+
};
|
|
159
|
+
const token = await (0, jwt_1.createJwtTokenString)(jsonToken, this.derivedTokenSigningSecret);
|
|
160
|
+
return { token, jsonToken };
|
|
137
161
|
}
|
|
138
|
-
async createRefreshToken() {
|
|
139
|
-
const
|
|
162
|
+
async createRefreshToken(subject, sessionId, expirationTimestamp) {
|
|
163
|
+
const secret = (0, random_1.getRandomString)(64, alphabet_1.Alphabet.LowerUpperCaseNumbers);
|
|
140
164
|
const salt = (0, random_1.getRandomBytes)(32);
|
|
141
|
-
const hash = await this.getHash(
|
|
142
|
-
|
|
165
|
+
const hash = await this.getHash(secret, salt);
|
|
166
|
+
const jsonToken = {
|
|
167
|
+
header: {
|
|
168
|
+
alg: 'HS256',
|
|
169
|
+
typ: 'JWT'
|
|
170
|
+
},
|
|
171
|
+
payload: {
|
|
172
|
+
exp: (0, date_time_1.timestampToTimestampSeconds)(expirationTimestamp),
|
|
173
|
+
subject,
|
|
174
|
+
sessionId,
|
|
175
|
+
secret
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const token = await (0, jwt_1.createJwtTokenString)(jsonToken, this.derivedRefreshTokenSigningSecret);
|
|
179
|
+
return { token, jsonToken, salt, hash: new Uint8Array(hash) };
|
|
180
|
+
}
|
|
181
|
+
async deriveSigningSecrets() {
|
|
182
|
+
const key = await (0, cryptography_1.importPbkdf2Key)(this.secret);
|
|
183
|
+
const hash = await globalThis.crypto.subtle.deriveBits({ name: 'PBKDF2', hash: 'SHA-512', iterations: 500000, salt: new Uint8Array() }, key, SIGNING_SECRETS_LENGTH * 2);
|
|
184
|
+
const bufferSize = SIGNING_SECRETS_LENGTH / 8;
|
|
185
|
+
this.derivedTokenSigningSecret = new Uint8Array(hash.slice(0, bufferSize));
|
|
186
|
+
this.derivedRefreshTokenSigningSecret = new Uint8Array(hash.slice(bufferSize));
|
|
143
187
|
}
|
|
144
188
|
async getHash(secret, salt) {
|
|
145
189
|
const key = await (0, cryptography_1.importPbkdf2Key)(secret);
|
|
@@ -149,6 +193,7 @@ let AuthenticationService = class AuthenticationService {
|
|
|
149
193
|
};
|
|
150
194
|
AuthenticationService = __decorate([
|
|
151
195
|
(0, container_1.singleton)(),
|
|
196
|
+
__param(2, (0, container_1.optional)()),
|
|
152
197
|
__param(3, (0, container_1.inject)(tokens_1.AUTHENTICATION_SERVICE_OPTIONS)),
|
|
153
198
|
__metadata("design:paramtypes", [authentication_credentials_repository_1.AuthenticationCredentialsRepository,
|
|
154
199
|
authentication_session_repository_1.AuthenticationSessionRepository,
|