@tsed/passport 7.0.0-beta.2 → 7.0.0-beta.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/jest.config.js +14 -0
- package/lib/cjs/PassportModule.js +27 -14
- package/lib/cjs/PassportModule.js.map +1 -1
- package/lib/cjs/contants/{index.js → constants.js} +1 -1
- package/lib/cjs/contants/constants.js.map +1 -0
- package/lib/cjs/decorators/authenticate.js +3 -3
- package/lib/cjs/decorators/authenticate.js.map +1 -1
- package/lib/cjs/decorators/authorize.js +3 -3
- package/lib/cjs/decorators/authorize.js.map +1 -1
- package/lib/cjs/decorators/protocol.js +2 -2
- package/lib/cjs/decorators/protocol.js.map +1 -1
- package/lib/cjs/domain/UserInfo.js +9 -6
- package/lib/cjs/domain/UserInfo.js.map +1 -1
- package/lib/cjs/index.js +21 -16
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/BeforeInstall.js +3 -0
- package/lib/cjs/interfaces/BeforeInstall.js.map +1 -0
- package/lib/cjs/interfaces/OnInstall.js.map +1 -1
- package/lib/cjs/interfaces/ProtocolMethods.js +3 -0
- package/lib/cjs/interfaces/ProtocolMethods.js.map +1 -0
- package/lib/cjs/interfaces/ProtocolOptions.js.map +1 -1
- package/lib/cjs/interfaces/{IProtocol.js → interfaces.js} +1 -1
- package/lib/cjs/interfaces/interfaces.js.map +1 -0
- package/lib/cjs/middlewares/PassportMiddleware.js +13 -10
- package/lib/cjs/middlewares/PassportMiddleware.js.map +1 -1
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/services/PassportSerializerService.js +5 -4
- package/lib/cjs/services/PassportSerializerService.js.map +1 -1
- package/lib/cjs/services/ProtocolsService.js +35 -22
- package/lib/cjs/services/ProtocolsService.js.map +1 -1
- package/lib/esm/PassportModule.js +18 -5
- package/lib/esm/PassportModule.js.map +1 -1
- package/lib/esm/contants/{index.js → constants.js} +1 -1
- package/lib/esm/contants/constants.js.map +1 -0
- package/lib/esm/decorators/authenticate.js +2 -2
- package/lib/esm/decorators/authenticate.js.map +1 -1
- package/lib/esm/decorators/authorize.js +2 -2
- package/lib/esm/decorators/authorize.js.map +1 -1
- package/lib/esm/decorators/protocol.js +1 -1
- package/lib/esm/decorators/protocol.js.map +1 -1
- package/lib/esm/domain/UserInfo.js +3 -0
- package/lib/esm/domain/UserInfo.js.map +1 -1
- package/lib/esm/index.js +21 -16
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/BeforeInstall.js +2 -0
- package/lib/esm/interfaces/BeforeInstall.js.map +1 -0
- package/lib/esm/interfaces/OnInstall.js.map +1 -1
- package/lib/esm/interfaces/ProtocolMethods.js +2 -0
- package/lib/esm/interfaces/ProtocolMethods.js.map +1 -0
- package/lib/esm/interfaces/ProtocolOptions.js.map +1 -1
- package/lib/esm/interfaces/interfaces.js +2 -0
- package/lib/esm/interfaces/interfaces.js.map +1 -0
- package/lib/esm/middlewares/PassportMiddleware.js +6 -3
- package/lib/esm/middlewares/PassportMiddleware.js.map +1 -1
- package/lib/esm/package.json +3 -0
- package/lib/esm/services/PassportSerializerService.js +3 -2
- package/lib/esm/services/PassportSerializerService.js.map +1 -1
- package/lib/esm/services/ProtocolsService.js +34 -21
- package/lib/esm/services/ProtocolsService.js.map +1 -1
- package/lib/types/PassportModule.d.ts +2 -1
- package/lib/types/contants/{index.d.ts → constants.d.ts} +0 -0
- package/lib/types/index.d.ts +15 -6
- package/lib/types/interfaces/BeforeInstall.d.ts +3 -0
- package/lib/types/interfaces/OnInstall.d.ts +1 -1
- package/lib/types/interfaces/ProtocolMethods.d.ts +5 -0
- package/lib/types/interfaces/ProtocolOptions.d.ts +2 -2
- package/lib/types/interfaces/{index.d.ts → interfaces.d.ts} +3 -4
- package/lib/types/services/ProtocolsService.d.ts +6 -5
- package/package.json +26 -22
- package/readme.md +18 -19
- package/tsconfig.compile.esm.json +1 -12
- package/lib/cjs/contants/index.js.map +0 -1
- package/lib/cjs/interfaces/IProtocol.js.map +0 -1
- package/lib/cjs/interfaces/index.js +0 -8
- package/lib/cjs/interfaces/index.js.map +0 -1
- package/lib/esm/contants/index.js.map +0 -1
- package/lib/esm/interfaces/IProtocol.js +0 -2
- package/lib/esm/interfaces/IProtocol.js.map +0 -1
- package/lib/esm/interfaces/index.js +0 -5
- package/lib/esm/interfaces/index.js.map +0 -1
- package/lib/types/interfaces/IProtocol.d.ts +0 -4
package/jest.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// For a detailed explanation regarding each configuration property, visit:
|
|
2
|
+
// https://jestjs.io/docs/en/configuration.html
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
...require("@tsed/jest-config")(__dirname, "passport"),
|
|
6
|
+
coverageThreshold: {
|
|
7
|
+
global: {
|
|
8
|
+
statements: 99.36,
|
|
9
|
+
branches: 80,
|
|
10
|
+
functions: 100,
|
|
11
|
+
lines: 99.32
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -3,22 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PassportModule = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const common_1 = require("@tsed/common");
|
|
6
|
-
const passport_1 =
|
|
6
|
+
const passport_1 = tslib_1.__importDefault(require("passport"));
|
|
7
7
|
const PassportSerializerService_1 = require("./services/PassportSerializerService");
|
|
8
8
|
const ProtocolsService_1 = require("./services/ProtocolsService");
|
|
9
9
|
/**
|
|
10
10
|
* @ignore
|
|
11
11
|
*/
|
|
12
12
|
let PassportModule = class PassportModule {
|
|
13
|
+
app;
|
|
14
|
+
protocolsService;
|
|
15
|
+
passportSerializer;
|
|
16
|
+
userProperty;
|
|
17
|
+
pauseStream;
|
|
18
|
+
disableSession;
|
|
19
|
+
platformName;
|
|
20
|
+
logger;
|
|
13
21
|
constructor(app, protocolsService, passportSerializer) {
|
|
14
22
|
this.app = app;
|
|
15
23
|
this.protocolsService = protocolsService;
|
|
16
24
|
this.passportSerializer = passportSerializer;
|
|
17
25
|
}
|
|
18
|
-
$onInit() {
|
|
26
|
+
async $onInit() {
|
|
19
27
|
passport_1.default.serializeUser(this.passportSerializer.serialize.bind(this.passportSerializer));
|
|
20
28
|
passport_1.default.deserializeUser(this.passportSerializer.deserialize.bind(this.passportSerializer));
|
|
21
|
-
this.protocolsService.getProtocols().
|
|
29
|
+
const promises = this.protocolsService.getProtocols().map((provider) => this.protocolsService.invoke(provider));
|
|
30
|
+
await Promise.all(promises);
|
|
22
31
|
return undefined;
|
|
23
32
|
}
|
|
24
33
|
$beforeRoutesInit() {
|
|
@@ -26,34 +35,38 @@ let PassportModule = class PassportModule {
|
|
|
26
35
|
switch (this.platformName) {
|
|
27
36
|
case "express":
|
|
28
37
|
this.app.use(passport_1.default.initialize({ userProperty }));
|
|
29
|
-
this.app.use(passport_1.default.session({ pauseStream }));
|
|
38
|
+
!this.disableSession && this.app.use(passport_1.default.session({ pauseStream }));
|
|
30
39
|
return;
|
|
31
40
|
default:
|
|
32
41
|
this.logger.warn(`Platform "${this.platformName}" not supported by @tsed/passport`);
|
|
33
42
|
}
|
|
34
43
|
}
|
|
35
44
|
};
|
|
36
|
-
|
|
45
|
+
tslib_1.__decorate([
|
|
37
46
|
(0, common_1.Constant)("passport.userProperty"),
|
|
38
|
-
|
|
47
|
+
tslib_1.__metadata("design:type", String)
|
|
39
48
|
], PassportModule.prototype, "userProperty", void 0);
|
|
40
|
-
|
|
49
|
+
tslib_1.__decorate([
|
|
41
50
|
(0, common_1.Constant)("passport.pauseStream"),
|
|
42
|
-
|
|
51
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
43
52
|
], PassportModule.prototype, "pauseStream", void 0);
|
|
44
|
-
|
|
53
|
+
tslib_1.__decorate([
|
|
54
|
+
(0, common_1.Constant)("passport.disableSession", false),
|
|
55
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
56
|
+
], PassportModule.prototype, "disableSession", void 0);
|
|
57
|
+
tslib_1.__decorate([
|
|
45
58
|
(0, common_1.Constant)("PLATFORM_NAME"),
|
|
46
|
-
|
|
59
|
+
tslib_1.__metadata("design:type", String)
|
|
47
60
|
], PassportModule.prototype, "platformName", void 0);
|
|
48
|
-
|
|
61
|
+
tslib_1.__decorate([
|
|
49
62
|
(0, common_1.Inject)(),
|
|
50
|
-
|
|
63
|
+
tslib_1.__metadata("design:type", common_1.Logger)
|
|
51
64
|
], PassportModule.prototype, "logger", void 0);
|
|
52
|
-
PassportModule =
|
|
65
|
+
PassportModule = tslib_1.__decorate([
|
|
53
66
|
(0, common_1.Module)({
|
|
54
67
|
scope: common_1.ProviderScope.SINGLETON
|
|
55
68
|
}),
|
|
56
|
-
|
|
69
|
+
tslib_1.__metadata("design:paramtypes", [common_1.PlatformApplication,
|
|
57
70
|
ProtocolsService_1.ProtocolsService,
|
|
58
71
|
PassportSerializerService_1.PassportSerializerService])
|
|
59
72
|
], PassportModule);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PassportModule.js","sourceRoot":"","sources":["../../src/PassportModule.ts"],"names":[],"mappings":";;;;AAAA,yCAAsI;AACtI,
|
|
1
|
+
{"version":3,"file":"PassportModule.js","sourceRoot":"","sources":["../../src/PassportModule.ts"],"names":[],"mappings":";;;;AAAA,yCAAsI;AACtI,gEAAgC;AAChC,oFAA+E;AAC/E,kEAA6D;AAE7D;;GAEG;AAIH,IAAa,cAAc,GAA3B,MAAa,cAAc;IAiBf;IACA;IACA;IAjBV,YAAY,CAAS;IAGrB,WAAW,CAAU;IAGrB,cAAc,CAAU;IAGxB,YAAY,CAAS;IAGrB,MAAM,CAAS;IAEf,YACU,GAAwB,EACxB,gBAAkC,EAClC,kBAA6C;QAF7C,QAAG,GAAH,GAAG,CAAqB;QACxB,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,uBAAkB,GAAlB,kBAAkB,CAA2B;IACpD,CAAC;IAEJ,KAAK,CAAC,OAAO;QACX,kBAAQ,CA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GrB;IADC,IAAA,eAAM,GAAE;sCACD,eAAM;8CAAC;AAdJ,cAAc;IAH1B,IAAA,eAAM,EAAC;QACN,KAAK,EAAE,sBAAa,CAAC,SAAS;KAC/B,CAAC;6CAkBe,4BAAmB;QACN,mCAAgB;QACd,qDAAyB;GAnB5C,cAAc,CA6C1B;AA7CY,wCAAc","sourcesContent":["import {BeforeRoutesInit, Constant, Inject, Module, OnInit, PlatformApplication, Provider, ProviderScope, Logger} from \"@tsed/common\";\nimport Passport from \"passport\";\nimport {PassportSerializerService} from \"./services/PassportSerializerService\";\nimport {ProtocolsService} from \"./services/ProtocolsService\";\n\n/**\n * @ignore\n */\n@Module({\n scope: ProviderScope.SINGLETON\n})\nexport class PassportModule implements OnInit, BeforeRoutesInit {\n @Constant(\"passport.userProperty\")\n userProperty: string;\n\n @Constant(\"passport.pauseStream\")\n pauseStream: boolean;\n\n @Constant(\"passport.disableSession\", false)\n disableSession: boolean;\n\n @Constant(\"PLATFORM_NAME\")\n platformName: string;\n\n @Inject()\n logger: Logger;\n\n constructor(\n private app: PlatformApplication,\n private protocolsService: ProtocolsService,\n private passportSerializer: PassportSerializerService\n ) {}\n\n async $onInit(): Promise<any> {\n Passport.serializeUser(this.passportSerializer.serialize.bind(this.passportSerializer));\n Passport.deserializeUser(this.passportSerializer.deserialize.bind(this.passportSerializer));\n\n const promises = this.protocolsService.getProtocols().map((provider: Provider) => this.protocolsService.invoke(provider));\n\n await Promise.all(promises);\n return undefined;\n }\n\n $beforeRoutesInit(): void | Promise<any> {\n const {userProperty, pauseStream} = this;\n switch (this.platformName) {\n case \"express\":\n this.app.use(Passport.initialize({userProperty}));\n !this.disableSession && this.app.use(Passport.session({pauseStream}));\n\n return;\n\n default:\n this.logger.warn(`Platform \"${this.platformName}\" not supported by @tsed/passport`);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/contants/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG,UAAU,CAAC","sourcesContent":["export const PROVIDER_TYPE_PROTOCOL = \"protocol\";\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Authenticate = void 0;
|
|
4
|
-
const
|
|
5
|
-
const PassportMiddleware_1 = require("../middlewares/PassportMiddleware");
|
|
4
|
+
const platform_middlewares_1 = require("@tsed/platform-middlewares");
|
|
6
5
|
const core_1 = require("@tsed/core");
|
|
7
6
|
const schema_1 = require("@tsed/schema");
|
|
7
|
+
const PassportMiddleware_1 = require("../middlewares/PassportMiddleware");
|
|
8
8
|
function Authenticate(protocol = "*", options = {}) {
|
|
9
|
-
return (0, core_1.useDecorators)((0,
|
|
9
|
+
return (0, core_1.useDecorators)((0, platform_middlewares_1.UseAuth)(PassportMiddleware_1.PassportMiddleware, {
|
|
10
10
|
protocol,
|
|
11
11
|
method: "authenticate",
|
|
12
12
|
originalUrl: options.originalUrl === undefined ? true : options.originalUrl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../../../src/decorators/authenticate.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../../../src/decorators/authenticate.ts"],"names":[],"mappings":";;;AAAA,qEAAmD;AACnD,qCAAyC;AACzC,yCAAsC;AAEtC,0EAAqE;AAOrE,SAAgB,YAAY,CAAC,WAA8B,GAAG,EAAE,UAA+B,EAAE;IAC/F,OAAO,IAAA,oBAAa,EAClB,IAAA,8BAAO,EAAC,uCAAkB,EAAE;QAC1B,QAAQ;QACR,MAAM,EAAE,cAAc;QACtB,WAAW,EAAE,OAAO,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW;QAC3E,OAAO;KACR,CAAC,EACF,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC7D,OAAO,IAAA,iBAAQ,EAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAZD,oCAYC","sourcesContent":["import {UseAuth} from \"@tsed/platform-middlewares\";\nimport {useDecorators} from \"@tsed/core\";\nimport {Security} from \"@tsed/schema\";\nimport {AuthenticateOptions as PassportAuthenticateOptions} from \"passport\";\nimport {PassportMiddleware} from \"../middlewares/PassportMiddleware\";\n\nexport interface AuthenticateOptions extends PassportAuthenticateOptions {\n security?: Record<string, string[]>;\n originalUrl?: boolean;\n}\n\nexport function Authenticate(protocol: string | string[] = \"*\", options: AuthenticateOptions = {}): Function {\n return useDecorators(\n UseAuth(PassportMiddleware, {\n protocol,\n method: \"authenticate\",\n originalUrl: options.originalUrl === undefined ? true : options.originalUrl,\n options\n }),\n ...Object.entries(options.security || {}).map(([key, value]) => {\n return Security(key, ...value);\n })\n );\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Authorize = void 0;
|
|
4
|
-
const
|
|
5
|
-
const PassportMiddleware_1 = require("../middlewares/PassportMiddleware");
|
|
4
|
+
const platform_middlewares_1 = require("@tsed/platform-middlewares");
|
|
6
5
|
const core_1 = require("@tsed/core");
|
|
7
6
|
const schema_1 = require("@tsed/schema");
|
|
7
|
+
const PassportMiddleware_1 = require("../middlewares/PassportMiddleware");
|
|
8
8
|
function Authorize(protocol = "*", options = {}) {
|
|
9
|
-
return (0, core_1.useDecorators)((0,
|
|
9
|
+
return (0, core_1.useDecorators)((0, platform_middlewares_1.UseAuth)(PassportMiddleware_1.PassportMiddleware, {
|
|
10
10
|
protocol,
|
|
11
11
|
method: "authorize",
|
|
12
12
|
originalUrl: options.originalUrl === undefined ? true : options.originalUrl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../../src/decorators/authorize.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../../src/decorators/authorize.ts"],"names":[],"mappings":";;;AAAA,qEAAmD;AACnD,qCAAyC;AACzC,yCAAsC;AAEtC,0EAAqE;AAOrE,SAAgB,SAAS,CAAC,WAA8B,GAAG,EAAE,UAA4B,EAAE;IACzF,OAAO,IAAA,oBAAa,EAClB,IAAA,8BAAO,EAAC,uCAAkB,EAAE;QAC1B,QAAQ;QACR,MAAM,EAAE,WAAW;QACnB,WAAW,EAAE,OAAO,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW;QAC3E,OAAO;KACR,CAAC,EACF,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC7D,OAAO,IAAA,iBAAQ,EAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAZD,8BAYC","sourcesContent":["import {UseAuth} from \"@tsed/platform-middlewares\";\nimport {useDecorators} from \"@tsed/core\";\nimport {Security} from \"@tsed/schema\";\nimport {AuthenticateOptions} from \"passport\";\nimport {PassportMiddleware} from \"../middlewares/PassportMiddleware\";\n\nexport interface AuthorizeOptions extends AuthenticateOptions {\n security?: Record<string, string[]>;\n originalUrl?: boolean;\n}\n\nexport function Authorize(protocol: string | string[] = \"*\", options: AuthorizeOptions = {}): Function {\n return useDecorators(\n UseAuth(PassportMiddleware, {\n protocol,\n method: \"authorize\",\n originalUrl: options.originalUrl === undefined ? true : options.originalUrl,\n options\n }),\n ...Object.entries(options.security || {}).map(([key, value]) => {\n return Security(key, ...value);\n })\n );\n}\n"]}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Protocol = void 0;
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
5
|
const di_1 = require("@tsed/di");
|
|
6
|
-
const
|
|
6
|
+
const constants_1 = require("../contants/constants");
|
|
7
7
|
/**
|
|
8
8
|
* Declare a new Protocol base on a Passport Strategy
|
|
9
9
|
*
|
|
@@ -12,7 +12,7 @@ const contants_1 = require("../contants");
|
|
|
12
12
|
*/
|
|
13
13
|
function Protocol(options) {
|
|
14
14
|
return (0, core_1.useDecorators)((0, di_1.Injectable)({
|
|
15
|
-
type:
|
|
15
|
+
type: constants_1.PROVIDER_TYPE_PROTOCOL
|
|
16
16
|
}), (0, core_1.StoreSet)("protocol", options), (0, di_1.Configuration)({
|
|
17
17
|
passport: {
|
|
18
18
|
protocols: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/decorators/protocol.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AACnD,iCAAmD;AAEnD,
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/decorators/protocol.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AACnD,iCAAmD;AAEnD,qDAA6D;AAE7D;;;;;GAKG;AACH,SAAgB,QAAQ,CAAU,OAAoC;IACpE,OAAO,IAAA,oBAAa,EAClB,IAAA,eAAU,EAAC;QACT,IAAI,EAAE,kCAAsB;KAC7B,CAAC,EACF,IAAA,eAAQ,EAAC,UAAU,EAAE,OAAO,CAAC,EAC7B,IAAA,kBAAa,EAAC;QACZ,QAAQ,EAAE;YACR,SAAS,EAAE;gBACT,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO;aACxB;SACF;KACF,CAAC,CACH,CAAC;AACJ,CAAC;AAdD,4BAcC","sourcesContent":["import {StoreSet, useDecorators} from \"@tsed/core\";\nimport {Configuration, Injectable} from \"@tsed/di\";\nimport {ProtocolOptions} from \"../interfaces/ProtocolOptions\";\nimport {PROVIDER_TYPE_PROTOCOL} from \"../contants/constants\";\n\n/**\n * Declare a new Protocol base on a Passport Strategy\n *\n * @decorator\n * @class\n */\nexport function Protocol<T = any>(options: ProtocolOptionsDecorator<T>) {\n return useDecorators(\n Injectable({\n type: PROVIDER_TYPE_PROTOCOL\n }),\n StoreSet(\"protocol\", options),\n Configuration({\n passport: {\n protocols: {\n [options.name]: options\n }\n }\n })\n );\n}\n\nexport type ProtocolOptionsDecorator<T = any> = {name: string} & Partial<ProtocolOptions<T>>;\n"]}
|
|
@@ -4,19 +4,22 @@ exports.UserInfo = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const schema_1 = require("@tsed/schema");
|
|
6
6
|
class UserInfo {
|
|
7
|
+
id;
|
|
8
|
+
email;
|
|
9
|
+
password;
|
|
7
10
|
}
|
|
8
|
-
|
|
11
|
+
tslib_1.__decorate([
|
|
9
12
|
(0, schema_1.Property)(),
|
|
10
|
-
|
|
13
|
+
tslib_1.__metadata("design:type", String)
|
|
11
14
|
], UserInfo.prototype, "id", void 0);
|
|
12
|
-
|
|
15
|
+
tslib_1.__decorate([
|
|
13
16
|
(0, schema_1.Property)(),
|
|
14
17
|
(0, schema_1.Format)("email"),
|
|
15
|
-
|
|
18
|
+
tslib_1.__metadata("design:type", String)
|
|
16
19
|
], UserInfo.prototype, "email", void 0);
|
|
17
|
-
|
|
20
|
+
tslib_1.__decorate([
|
|
18
21
|
(0, schema_1.Property)(),
|
|
19
|
-
|
|
22
|
+
tslib_1.__metadata("design:type", String)
|
|
20
23
|
], UserInfo.prototype, "password", void 0);
|
|
21
24
|
exports.UserInfo = UserInfo;
|
|
22
25
|
//# sourceMappingURL=UserInfo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserInfo.js","sourceRoot":"","sources":["../../../src/domain/UserInfo.ts"],"names":[],"mappings":";;;;AAAA,yCAA8C;AAE9C,MAAa,QAAQ;
|
|
1
|
+
{"version":3,"file":"UserInfo.js","sourceRoot":"","sources":["../../../src/domain/UserInfo.ts"],"names":[],"mappings":";;;;AAAA,yCAA8C;AAE9C,MAAa,QAAQ;IAEnB,EAAE,CAAS;IAIX,KAAK,CAAS;IAGd,QAAQ,CAAS;CAClB;AARC;IADC,IAAA,iBAAQ,GAAE;;oCACA;AAIX;IAFC,IAAA,iBAAQ,GAAE;IACV,IAAA,eAAM,EAAC,OAAO,CAAC;;uCACF;AAGd;IADC,IAAA,iBAAQ,GAAE;;0CACM;AATnB,4BAUC","sourcesContent":["import {Format, Property} from \"@tsed/schema\";\n\nexport class UserInfo {\n @Property()\n id: string;\n\n @Property()\n @Format(\"email\")\n email: string;\n\n @Property()\n password: string;\n}\n"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Automatically generated by barrelsby.
|
|
4
|
+
*/
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const tslib_1 = require("tslib");
|
|
4
|
-
require("./PassportModule");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
tslib_1.__exportStar(require("./PassportModule"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./contants/constants"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./decorators/args"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./decorators/authenticate"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./decorators/authorize"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./decorators/protocol"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./domain/UserInfo"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./errors/PassportException"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./interfaces/BeforeInstall"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./interfaces/OnInstall"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./interfaces/OnVerify"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./interfaces/ProtocolMethods"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./interfaces/ProtocolOptions"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./middlewares/PassportMiddleware"), exports);
|
|
22
|
+
tslib_1.__exportStar(require("./services/PassportSerializerService"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./services/ProtocolsService"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./utils/getProtocolsFromRequest"), exports);
|
|
20
25
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,2DAAiC;AACjC,+DAAqC;AACrC,4DAAkC;AAClC,oEAA0C;AAC1C,iEAAuC;AACvC,gEAAsC;AACtC,4DAAkC;AAClC,qEAA2C;AAC3C,qEAA2C;AAC3C,iEAAuC;AACvC,gEAAsC;AACtC,uEAA6C;AAC7C,uEAA6C;AAC7C,kEAAwC;AACxC,2EAAiD;AACjD,+EAAqD;AACrD,sEAA4C;AAC5C,0EAAgD","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./PassportModule\";\nexport * from \"./contants/constants\";\nexport * from \"./decorators/args\";\nexport * from \"./decorators/authenticate\";\nexport * from \"./decorators/authorize\";\nexport * from \"./decorators/protocol\";\nexport * from \"./domain/UserInfo\";\nexport * from \"./errors/PassportException\";\nexport * from \"./interfaces/BeforeInstall\";\nexport * from \"./interfaces/OnInstall\";\nexport * from \"./interfaces/OnVerify\";\nexport * from \"./interfaces/ProtocolMethods\";\nexport * from \"./interfaces/ProtocolOptions\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/PassportMiddleware\";\nexport * from \"./services/PassportSerializerService\";\nexport * from \"./services/ProtocolsService\";\nexport * from \"./utils/getProtocolsFromRequest\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BeforeInstall.js","sourceRoot":"","sources":["../../../src/interfaces/BeforeInstall.ts"],"names":[],"mappings":"","sourcesContent":["export interface BeforeInstall<Settings = any> {\n $beforeInstall(setting: Settings): Promise<Settings> | Settings | void;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OnInstall.js","sourceRoot":"","sources":["../../../src/interfaces/OnInstall.ts"],"names":[],"mappings":"","sourcesContent":["import {Strategy} from \"passport\";\n\nexport interface OnInstall {\n $onInstall(strategy: Strategy): void
|
|
1
|
+
{"version":3,"file":"OnInstall.js","sourceRoot":"","sources":["../../../src/interfaces/OnInstall.ts"],"names":[],"mappings":"","sourcesContent":["import {Strategy} from \"passport\";\n\nexport interface OnInstall {\n $onInstall(strategy: Strategy): void | Promise<void>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProtocolMethods.js","sourceRoot":"","sources":["../../../src/interfaces/ProtocolMethods.ts"],"names":[],"mappings":"","sourcesContent":["import {OnInstall} from \"./OnInstall\";\nimport {OnVerify} from \"./OnVerify\";\nimport {BeforeInstall} from \"./BeforeInstall\";\n\nexport interface ProtocolMethods<Settings = any> extends OnVerify, OnInstall, BeforeInstall<Settings> {}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProtocolOptions.js","sourceRoot":"","sources":["../../../src/interfaces/ProtocolOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {Strategy} from \"passport\";\n\nexport interface ProtocolOptions<
|
|
1
|
+
{"version":3,"file":"ProtocolOptions.js","sourceRoot":"","sources":["../../../src/interfaces/ProtocolOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {Strategy} from \"passport\";\n\nexport interface ProtocolOptions<Settings = any> {\n name: string;\n useStrategy: Type<Strategy>;\n settings: Settings;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {PassportStatic} from \"passport\";\nimport {ProtocolOptions} from \"./ProtocolOptions\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n passport: {\n userProperty?: string;\n pauseStream?: string;\n disableSession?: boolean;\n userInfoModel?: Type<any> | false;\n module?: PassportStatic;\n protocols?: {\n [protocolName: string]: Partial<ProtocolOptions>;\n };\n };\n }\n }\n}\n"]}
|
|
@@ -3,10 +3,13 @@ var PassportMiddleware_1;
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.PassportMiddleware = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
|
+
const di_1 = require("@tsed/di");
|
|
7
|
+
const platform_middlewares_1 = require("@tsed/platform-middlewares");
|
|
6
8
|
const common_1 = require("@tsed/common");
|
|
7
9
|
const ProtocolsService_1 = require("../services/ProtocolsService");
|
|
8
10
|
const getProtocolsFromRequest_1 = require("../utils/getProtocolsFromRequest");
|
|
9
11
|
let PassportMiddleware = PassportMiddleware_1 = class PassportMiddleware {
|
|
12
|
+
protocolsService;
|
|
10
13
|
shouldSkip(ctx) {
|
|
11
14
|
const request = ctx.getRequest();
|
|
12
15
|
return request.user && request.isAuthenticated();
|
|
@@ -27,18 +30,18 @@ let PassportMiddleware = PassportMiddleware_1 = class PassportMiddleware {
|
|
|
27
30
|
: this.protocolsService.authorize(protocols, options, ctx));
|
|
28
31
|
}
|
|
29
32
|
};
|
|
30
|
-
|
|
31
|
-
(0,
|
|
32
|
-
|
|
33
|
+
tslib_1.__decorate([
|
|
34
|
+
(0, di_1.Inject)(ProtocolsService_1.ProtocolsService),
|
|
35
|
+
tslib_1.__metadata("design:type", ProtocolsService_1.ProtocolsService)
|
|
33
36
|
], PassportMiddleware.prototype, "protocolsService", void 0);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
tslib_1.__decorate([
|
|
38
|
+
tslib_1.__param(0, (0, common_1.Context)()),
|
|
39
|
+
tslib_1.__metadata("design:type", Function),
|
|
40
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
41
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
39
42
|
], PassportMiddleware.prototype, "use", null);
|
|
40
|
-
PassportMiddleware = PassportMiddleware_1 =
|
|
41
|
-
(0,
|
|
43
|
+
PassportMiddleware = PassportMiddleware_1 = tslib_1.__decorate([
|
|
44
|
+
(0, platform_middlewares_1.Middleware)()
|
|
42
45
|
], PassportMiddleware);
|
|
43
46
|
exports.PassportMiddleware = PassportMiddleware;
|
|
44
47
|
//# sourceMappingURL=PassportMiddleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PassportMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PassportMiddleware.ts"],"names":[],"mappings":";;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"PassportMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PassportMiddleware.ts"],"names":[],"mappings":";;;;;AAAA,iCAAgC;AAChC,qEAAsD;AACtD,yCAAqC;AACrC,mEAA8D;AAC9D,8EAAyE;AAGzE,IAA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DAAkB","sourcesContent":["import {Inject} from \"@tsed/di\";\nimport {Middleware} from \"@tsed/platform-middlewares\";\nimport {Context} from \"@tsed/common\";\nimport {ProtocolsService} from \"../services/ProtocolsService\";\nimport {getProtocolsFromRequest} from \"../utils/getProtocolsFromRequest\";\n\n@Middleware()\nexport class PassportMiddleware {\n @Inject(ProtocolsService)\n protocolsService: ProtocolsService;\n\n shouldSkip(ctx: Context) {\n const request = ctx.getRequest();\n return request.user && request.isAuthenticated();\n }\n\n async use(@Context() ctx: Context) {\n const endpoint = ctx.endpoint;\n const request = ctx.getRequest();\n\n if (this.shouldSkip(ctx)) {\n return;\n }\n const {options, protocol, method, originalUrl = true} = endpoint.store.get(PassportMiddleware);\n const protocols = getProtocolsFromRequest(request, protocol, this.protocolsService.getProtocolsNames());\n\n if (originalUrl) {\n request.url = request.originalUrl;\n }\n\n await (method === \"authenticate\"\n ? this.protocolsService.authenticate(protocols, options, ctx)\n : this.protocolsService.authorize(protocols, options, ctx));\n }\n}\n"]}
|
|
@@ -9,11 +9,12 @@ const UserInfo_1 = require("../domain/UserInfo");
|
|
|
9
9
|
* @ignore
|
|
10
10
|
*/
|
|
11
11
|
let PassportSerializerService = class PassportSerializerService {
|
|
12
|
+
model;
|
|
12
13
|
serialize(user, done) {
|
|
13
14
|
try {
|
|
14
15
|
const obj = (0, json_mapper_1.serialize)(user, { type: this.model });
|
|
15
16
|
// remove password from serialized object
|
|
16
|
-
|
|
17
|
+
obj.password = undefined;
|
|
17
18
|
done(null, JSON.stringify(obj));
|
|
18
19
|
}
|
|
19
20
|
catch (er) {
|
|
@@ -31,11 +32,11 @@ let PassportSerializerService = class PassportSerializerService {
|
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
};
|
|
34
|
-
|
|
35
|
+
tslib_1.__decorate([
|
|
35
36
|
(0, di_1.Constant)("passport.userInfoModel", UserInfo_1.UserInfo),
|
|
36
|
-
|
|
37
|
+
tslib_1.__metadata("design:type", Object)
|
|
37
38
|
], PassportSerializerService.prototype, "model", void 0);
|
|
38
|
-
PassportSerializerService =
|
|
39
|
+
PassportSerializerService = tslib_1.__decorate([
|
|
39
40
|
(0, di_1.Service)()
|
|
40
41
|
], PassportSerializerService);
|
|
41
42
|
exports.PassportSerializerService = PassportSerializerService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PassportSerializerService.js","sourceRoot":"","sources":["../../../src/services/PassportSerializerService.ts"],"names":[],"mappings":";;;;AACA,iCAA2C;AAC3C,mDAAyD;AACzD,iDAA4C;AAE5C;;GAEG;AAEH,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;
|
|
1
|
+
{"version":3,"file":"PassportSerializerService.js","sourceRoot":"","sources":["../../../src/services/PassportSerializerService.ts"],"names":[],"mappings":";;;;AACA,iCAA2C;AAC3C,mDAAyD;AACzD,iDAA4C;AAE5C;;GAEG;AAEH,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IAE5B,KAAK,CAA2B;IAExC,SAAS,CAAC,IAAc,EAAE,IAAS;QACjC,IAAI;YACF,MAAM,GAAG,GAAG,IAAA,uBAAS,EAAC,IAAI,EAAE,EAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAC,CAAC,CAAC;YAEhD,yCAAyC;YACzC,GAAG,CAAC,QAAQ,GAAG,SAAS,CAAC;YAEzB,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;SACjC;QAAC,OAAO,EAAE,EAAE;YACX,uBAAuB;YACvB,IAAI,CAAC,EAAE,CAAC,CAAC;SACV;IACH,CAAC;IAED,WAAW,CAAC,GAAQ,EAAE,IAAS;QAC7B,IAAI;YACF,MAAM,IAAI,GAAG,IAAA,yBAAW,EAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,EAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAC,CAAC,CAAC;YAE9D,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SAClB;QAAC,OAAO,EAAE,EAAE;YACX,IAAI,CAAC,EAAE,CAAC,CAAC;SACV;IACH,CAAC;CACF,CAAA;AAzBC;IADC,IAAA,aAAQ,EAAC,wBAAwB,EAAE,mBAAQ,CAAC;;wDACL;AAF7B,yBAAyB;IADrC,IAAA,YAAO,GAAE;GACG,yBAAyB,CA2BrC;AA3BY,8DAAyB","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {Constant, Service} from \"@tsed/di\";\nimport {deserialize, serialize} from \"@tsed/json-mapper\";\nimport {UserInfo} from \"../domain/UserInfo\";\n\n/**\n * @ignore\n */\n@Service()\nexport class PassportSerializerService {\n @Constant(\"passport.userInfoModel\", UserInfo)\n private model: Type<UserInfo> | boolean;\n\n serialize(user: UserInfo, done: any) {\n try {\n const obj = serialize(user, {type: this.model});\n\n // remove password from serialized object\n obj.password = undefined;\n\n done(null, JSON.stringify(obj));\n } catch (er) {\n // istanbul ignore next\n done(er);\n }\n }\n\n deserialize(obj: any, done: any) {\n try {\n const user = deserialize(JSON.parse(obj), {type: this.model});\n\n done(null, user);\n } catch (er) {\n done(er);\n }\n }\n}\n"]}
|
|
@@ -6,20 +6,19 @@ const common_1 = require("@tsed/common");
|
|
|
6
6
|
const core_1 = require("@tsed/core");
|
|
7
7
|
const di_1 = require("@tsed/di");
|
|
8
8
|
const exceptions_1 = require("@tsed/exceptions");
|
|
9
|
-
const passport_1 =
|
|
10
|
-
const PassportException_1 = require("../errors/PassportException");
|
|
11
|
-
const contants_1 = require("../contants");
|
|
9
|
+
const passport_1 = tslib_1.__importStar(require("passport"));
|
|
12
10
|
const util_1 = require("util");
|
|
11
|
+
const constants_1 = require("../contants/constants");
|
|
12
|
+
const PassportException_1 = require("../errors/PassportException");
|
|
13
13
|
/**
|
|
14
14
|
* @ignore
|
|
15
15
|
*/
|
|
16
16
|
let ProtocolsService = class ProtocolsService {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
17
|
+
strategies = new Map();
|
|
18
|
+
platformHandler;
|
|
19
|
+
injector;
|
|
21
20
|
getProtocols() {
|
|
22
|
-
return
|
|
21
|
+
return this.injector.getProviders(constants_1.PROVIDER_TYPE_PROTOCOL);
|
|
23
22
|
}
|
|
24
23
|
getProtocolsNames() {
|
|
25
24
|
return Array.from(this.strategies.keys());
|
|
@@ -28,14 +27,17 @@ let ProtocolsService = class ProtocolsService {
|
|
|
28
27
|
* Invoke provider and bind it to passport.
|
|
29
28
|
* @param provider
|
|
30
29
|
*/
|
|
31
|
-
invoke(provider) {
|
|
32
|
-
|
|
30
|
+
async invoke(provider) {
|
|
31
|
+
let { name, useStrategy: strategy, settings } = this.getOptions(provider);
|
|
33
32
|
const protocol = this.injector.get(provider.provide);
|
|
33
|
+
if (protocol.$beforeInstall) {
|
|
34
|
+
settings = (await protocol.$beforeInstall(settings)) || settings;
|
|
35
|
+
}
|
|
34
36
|
const instance = new strategy(settings, this.createHandler(provider));
|
|
35
37
|
this.strategies.set(name, instance);
|
|
36
38
|
passport_1.default.use(name, instance);
|
|
37
39
|
if (protocol.$onInstall) {
|
|
38
|
-
protocol.$onInstall(instance);
|
|
40
|
+
await protocol.$onInstall(instance);
|
|
39
41
|
}
|
|
40
42
|
protocol.$strategy = instance;
|
|
41
43
|
return protocol;
|
|
@@ -109,24 +111,35 @@ let ProtocolsService = class ProtocolsService {
|
|
|
109
111
|
* @private
|
|
110
112
|
*/
|
|
111
113
|
createHandler(provider) {
|
|
112
|
-
const
|
|
113
|
-
const middleware = platformHandler.createCustomHandler(provider, "$onVerify");
|
|
114
|
+
const middleware = this.platformHandler.createCustomHandler(provider, "$onVerify");
|
|
114
115
|
return async (req, ...args) => {
|
|
115
116
|
const done = args[args.length - 1];
|
|
116
|
-
req.$ctx
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
if (req.$ctx) {
|
|
118
|
+
req.$ctx.set("PROTOCOL_ARGS", args.slice(0, -1));
|
|
119
|
+
try {
|
|
120
|
+
await middleware(req.$ctx);
|
|
121
|
+
done(null, ...[].concat(req.$ctx.data));
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
done(err, false, { message: err.message });
|
|
125
|
+
}
|
|
120
126
|
}
|
|
121
|
-
|
|
122
|
-
done(
|
|
127
|
+
else {
|
|
128
|
+
done(new Error("Headers already sent"), false, { message: "Headers already sent" });
|
|
123
129
|
}
|
|
124
130
|
};
|
|
125
131
|
}
|
|
126
132
|
};
|
|
127
|
-
|
|
128
|
-
(0, di_1.
|
|
129
|
-
|
|
133
|
+
tslib_1.__decorate([
|
|
134
|
+
(0, di_1.Inject)(),
|
|
135
|
+
tslib_1.__metadata("design:type", common_1.PlatformHandler)
|
|
136
|
+
], ProtocolsService.prototype, "platformHandler", void 0);
|
|
137
|
+
tslib_1.__decorate([
|
|
138
|
+
(0, di_1.Inject)(),
|
|
139
|
+
tslib_1.__metadata("design:type", di_1.InjectorService)
|
|
140
|
+
], ProtocolsService.prototype, "injector", void 0);
|
|
141
|
+
ProtocolsService = tslib_1.__decorate([
|
|
142
|
+
(0, di_1.Injectable)()
|
|
130
143
|
], ProtocolsService);
|
|
131
144
|
exports.ProtocolsService = ProtocolsService;
|
|
132
145
|
//# sourceMappingURL=ProtocolsService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProtocolsService.js","sourceRoot":"","sources":["../../../src/services/ProtocolsService.ts"],"names":[],"mappings":";;;;AAAA,yCAA8D;AAC9D,qCAAuC;AACvC,
|
|
1
|
+
{"version":3,"file":"ProtocolsService.js","sourceRoot":"","sources":["../../../src/services/ProtocolsService.ts"],"names":[],"mappings":";;;;AAAA,yCAA8D;AAC9D,qCAAuC;AACvC,iCAAuE;AACvE,iDAA8C;AAC9C,6DAA4C;AAC5C,+BAA+B;AAC/B,qDAA6D;AAC7D,mEAA8D;AAI9D;;GAEG;AAEH,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAClB,UAAU,GAA0B,IAAI,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C,CAAC;IACJ,CAAC;CACF,CAAA;AA9IC;IADC,IAAA,WAAM,GAAE;sCACkB,wBAAe;yDAAC;AAG3C;IADC,IAAA,WAAM,GAAE;sCACS,oBAAe;kDAAC;AAPvB,gBAAgB;IAD5B,IAAA,eAAU,GAAE;GACA,gBAAgB,CAkJ5B;AAlJY,4CAAgB","sourcesContent":["import {PlatformContext, PlatformHandler} from \"@tsed/common\";\nimport {ancestorsOf} from \"@tsed/core\";\nimport {Inject, Injectable, InjectorService, Provider} from \"@tsed/di\";\nimport {Unauthorized} from \"@tsed/exceptions\";\nimport Passport, {Strategy} from \"passport\";\nimport {promisify} from \"util\";\nimport {PROVIDER_TYPE_PROTOCOL} from \"../contants/constants\";\nimport {PassportException} from \"../errors/PassportException\";\nimport type {ProtocolMethods} from \"../interfaces/ProtocolMethods\";\nimport type {ProtocolOptions} from \"../interfaces/ProtocolOptions\";\n\n/**\n * @ignore\n */\n@Injectable()\nexport class ProtocolsService {\n readonly strategies: Map<string, Strategy> = new Map();\n\n @Inject()\n protected platformHandler: PlatformHandler;\n\n @Inject()\n private injector: InjectorService;\n\n public getProtocols(): Provider[] {\n return this.injector.getProviders(PROVIDER_TYPE_PROTOCOL);\n }\n\n public getProtocolsNames(): string[] {\n return Array.from(this.strategies.keys());\n }\n\n /**\n * Invoke provider and bind it to passport.\n * @param provider\n */\n async invoke(provider: Provider) {\n let {name, useStrategy: strategy, settings} = this.getOptions(provider);\n const protocol = this.injector.get<ProtocolMethods & Record<string, any>>(provider.provide)!;\n\n if (protocol.$beforeInstall) {\n settings = (await protocol.$beforeInstall(settings)) || settings;\n }\n\n const instance = new strategy(settings, this.createHandler(provider));\n\n this.strategies.set(name, instance);\n\n Passport.use(name, instance);\n\n if (protocol.$onInstall) {\n await protocol.$onInstall(instance);\n }\n\n protocol.$strategy = instance;\n\n return protocol;\n }\n\n /**\n * Call authenticate passport method.\n * @param protocols\n * @param options\n * @param ctx\n */\n public async authenticate(protocols: string | string[], options: Record<string, any>, ctx: PlatformContext) {\n return this.call(\"authenticate\", protocols, options, ctx);\n }\n\n /**\n * Call authorize passport method.\n * @param protocols\n * @param options\n * @param ctx\n */\n public async authorize(protocols: string | string[], options: Record<string, any>, ctx: PlatformContext) {\n return this.call(\"authorize\", protocols, options, ctx);\n }\n\n /**\n * Call passport authenticate or authorize depending on the chosen method.\n * @param method\n * @param protocols\n * @param options\n * @param ctx\n * @private\n */\n private async call(\n method: \"authenticate\" | \"authorize\",\n protocols: string | string[],\n options: Record<string, any>,\n ctx: PlatformContext\n ) {\n const request = ctx.getRequest();\n const response = ctx.getResponse();\n protocols = ([] as string[]).concat(protocols);\n\n if (protocols.length === 0) {\n throw new Unauthorized(\"Not authorized\");\n }\n\n try {\n options.failWithError = true;\n // @ts-ignore\n const fn = promisify(Passport[method](protocols.length === 1 ? protocols[0] : protocols, options));\n\n await fn(request, response);\n } catch (er) {\n if (!ancestorsOf(er).includes(Error)) {\n throw new PassportException(er);\n }\n\n throw er;\n }\n }\n\n /**\n * Create strategy options based on decorator metadata and global configuration\n * @param provider\n * @private\n */\n private getOptions(provider: Provider<any>): ProtocolOptions {\n const {name} = provider.store.get(\"protocol\");\n const {useStrategy = Strategy, settings = {}}: ProtocolOptions = this.injector.settings.get(`passport.protocols.${name}`) || {};\n\n return {\n name,\n useStrategy,\n settings: {\n ...settings,\n passReqToCallback: true\n }\n };\n }\n\n /**\n * Create the verifier handler for passport\n * @param provider\n * @private\n */\n private createHandler(provider: Provider) {\n const middleware = this.platformHandler.createCustomHandler(provider, \"$onVerify\");\n\n return async (req: any, ...args: any[]) => {\n const done = args[args.length - 1];\n\n if (req.$ctx) {\n req.$ctx.set(\"PROTOCOL_ARGS\", args.slice(0, -1));\n\n try {\n await middleware(req.$ctx);\n\n done(null, ...[].concat(req.$ctx.data));\n } catch (err) {\n done(err, false, {message: err.message});\n }\n } else {\n done(new Error(\"Headers already sent\"), false, {message: \"Headers already sent\"});\n }\n };\n }\n}\n"]}
|