@tsed/passport 6.107.5 → 6.110.0
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 +1 -1
- package/lib/cjs/PassportModule.js +13 -13
- package/lib/cjs/PassportModule.js.map +1 -1
- package/lib/cjs/domain/UserInfo.js +6 -6
- package/lib/cjs/index.js +18 -18
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/middlewares/PassportMiddleware.js +8 -8
- package/lib/cjs/middlewares/PassportMiddleware.js.map +1 -1
- package/lib/cjs/services/PassportSerializerService.js +3 -3
- package/lib/cjs/services/ProtocolsService.js +4 -4
- package/lib/cjs/services/ProtocolsService.js.map +1 -1
- package/lib/esm/services/ProtocolsService.js +1 -1
- package/lib/esm/services/ProtocolsService.js.map +1 -1
- package/package.json +14 -14
package/jest.config.js
CHANGED
|
@@ -3,7 +3,7 @@ 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
|
/**
|
|
@@ -34,31 +34,31 @@ let PassportModule = class PassportModule {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
|
|
37
|
+
tslib_1.__decorate([
|
|
38
38
|
(0, common_1.Constant)("passport.userProperty"),
|
|
39
|
-
|
|
39
|
+
tslib_1.__metadata("design:type", String)
|
|
40
40
|
], PassportModule.prototype, "userProperty", void 0);
|
|
41
|
-
|
|
41
|
+
tslib_1.__decorate([
|
|
42
42
|
(0, common_1.Constant)("passport.pauseStream"),
|
|
43
|
-
|
|
43
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
44
44
|
], PassportModule.prototype, "pauseStream", void 0);
|
|
45
|
-
|
|
45
|
+
tslib_1.__decorate([
|
|
46
46
|
(0, common_1.Constant)("passport.disableSession", false),
|
|
47
|
-
|
|
47
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
48
48
|
], PassportModule.prototype, "disableSession", void 0);
|
|
49
|
-
|
|
49
|
+
tslib_1.__decorate([
|
|
50
50
|
(0, common_1.Constant)("PLATFORM_NAME"),
|
|
51
|
-
|
|
51
|
+
tslib_1.__metadata("design:type", String)
|
|
52
52
|
], PassportModule.prototype, "platformName", void 0);
|
|
53
|
-
|
|
53
|
+
tslib_1.__decorate([
|
|
54
54
|
(0, common_1.Inject)(),
|
|
55
|
-
|
|
55
|
+
tslib_1.__metadata("design:type", common_1.Logger)
|
|
56
56
|
], PassportModule.prototype, "logger", void 0);
|
|
57
|
-
PassportModule =
|
|
57
|
+
PassportModule = tslib_1.__decorate([
|
|
58
58
|
(0, common_1.Module)({
|
|
59
59
|
scope: common_1.ProviderScope.SINGLETON
|
|
60
60
|
}),
|
|
61
|
-
|
|
61
|
+
tslib_1.__metadata("design:paramtypes", [common_1.PlatformApplication,
|
|
62
62
|
ProtocolsService_1.ProtocolsService,
|
|
63
63
|
PassportSerializerService_1.PassportSerializerService])
|
|
64
64
|
], 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;IAgBzB,YACU,GAAwB,EACxB,gBAAkC,EAClC,kBAA6C;QAF7C,QAAG,GAAH,GAAG,CAAqB;QACxB,qBAAgB,G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C,IAAA,iBAAQ,EAAC,yBAAyB,EAAE,KAAK,CAAC;;sDACnB;AAGxB;IADC,IAAA,iBAAQ,EAAC,eAAe,CAAC;;oDACL;AAGrB;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"]}
|
|
@@ -5,18 +5,18 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const schema_1 = require("@tsed/schema");
|
|
6
6
|
class UserInfo {
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
tslib_1.__decorate([
|
|
9
9
|
(0, schema_1.Property)(),
|
|
10
|
-
|
|
10
|
+
tslib_1.__metadata("design:type", String)
|
|
11
11
|
], UserInfo.prototype, "id", void 0);
|
|
12
|
-
|
|
12
|
+
tslib_1.__decorate([
|
|
13
13
|
(0, schema_1.Property)(),
|
|
14
14
|
(0, schema_1.Format)("email"),
|
|
15
|
-
|
|
15
|
+
tslib_1.__metadata("design:type", String)
|
|
16
16
|
], UserInfo.prototype, "email", void 0);
|
|
17
|
-
|
|
17
|
+
tslib_1.__decorate([
|
|
18
18
|
(0, schema_1.Property)(),
|
|
19
|
-
|
|
19
|
+
tslib_1.__metadata("design:type", String)
|
|
20
20
|
], UserInfo.prototype, "password", void 0);
|
|
21
21
|
exports.UserInfo = UserInfo;
|
|
22
22
|
//# sourceMappingURL=UserInfo.js.map
|
package/lib/cjs/index.js
CHANGED
|
@@ -4,22 +4,22 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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);
|
|
25
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":";AAAA;;GAEG;;;AAEH,
|
|
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"]}
|
|
@@ -27,17 +27,17 @@ let PassportMiddleware = PassportMiddleware_1 = class PassportMiddleware {
|
|
|
27
27
|
: this.protocolsService.authorize(protocols, options, ctx));
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
-
|
|
30
|
+
tslib_1.__decorate([
|
|
31
31
|
(0, common_1.Inject)(ProtocolsService_1.ProtocolsService),
|
|
32
|
-
|
|
32
|
+
tslib_1.__metadata("design:type", ProtocolsService_1.ProtocolsService)
|
|
33
33
|
], PassportMiddleware.prototype, "protocolsService", void 0);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
tslib_1.__decorate([
|
|
35
|
+
tslib_1.__param(0, (0, common_1.Context)()),
|
|
36
|
+
tslib_1.__metadata("design:type", Function),
|
|
37
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
38
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
39
39
|
], PassportMiddleware.prototype, "use", null);
|
|
40
|
-
PassportMiddleware = PassportMiddleware_1 =
|
|
40
|
+
PassportMiddleware = PassportMiddleware_1 = tslib_1.__decorate([
|
|
41
41
|
(0, common_1.Middleware)()
|
|
42
42
|
], PassportMiddleware);
|
|
43
43
|
exports.PassportMiddleware = PassportMiddleware;
|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AAOnC;IAAW,mBAAA,IAAA,gBAAO,GAAE,CAAA;;;;6CAiBnB;AA1BU,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;GACA,kBAAkB,CA2B9B;AA3BY,gDAAkB","sourcesContent":["import {Context, Inject, Middleware} 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"]}
|
|
@@ -31,11 +31,11 @@ let PassportSerializerService = class PassportSerializerService {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
|
|
34
|
+
tslib_1.__decorate([
|
|
35
35
|
(0, di_1.Constant)("passport.userInfoModel", UserInfo_1.UserInfo),
|
|
36
|
-
|
|
36
|
+
tslib_1.__metadata("design:type", Object)
|
|
37
37
|
], PassportSerializerService.prototype, "model", void 0);
|
|
38
|
-
PassportSerializerService =
|
|
38
|
+
PassportSerializerService = tslib_1.__decorate([
|
|
39
39
|
(0, di_1.Service)()
|
|
40
40
|
], PassportSerializerService);
|
|
41
41
|
exports.PassportSerializerService = PassportSerializerService;
|
|
@@ -6,7 +6,7 @@ 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 =
|
|
9
|
+
const passport_1 = tslib_1.__importStar(require("passport"));
|
|
10
10
|
const PassportException_1 = require("../errors/PassportException");
|
|
11
11
|
const constants_1 = require("../contants/constants");
|
|
12
12
|
const util_1 = require("util");
|
|
@@ -19,7 +19,7 @@ let ProtocolsService = class ProtocolsService {
|
|
|
19
19
|
this.strategies = new Map();
|
|
20
20
|
}
|
|
21
21
|
getProtocols() {
|
|
22
|
-
return
|
|
22
|
+
return this.injector.getProviders(constants_1.PROVIDER_TYPE_PROTOCOL);
|
|
23
23
|
}
|
|
24
24
|
getProtocolsNames() {
|
|
25
25
|
return Array.from(this.strategies.keys());
|
|
@@ -132,9 +132,9 @@ let ProtocolsService = class ProtocolsService {
|
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
|
-
ProtocolsService =
|
|
135
|
+
ProtocolsService = tslib_1.__decorate([
|
|
136
136
|
(0, di_1.Injectable)(),
|
|
137
|
-
|
|
137
|
+
tslib_1.__metadata("design:paramtypes", [di_1.InjectorService])
|
|
138
138
|
], ProtocolsService);
|
|
139
139
|
exports.ProtocolsService = ProtocolsService;
|
|
140
140
|
//# 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,iCAA+D;AAC/D,iDAA8C;AAC9C,
|
|
1
|
+
{"version":3,"file":"ProtocolsService.js","sourceRoot":"","sources":["../../../src/services/ProtocolsService.ts"],"names":[],"mappings":";;;;AAAA,yCAA8D;AAC9D,qCAAuC;AACvC,iCAA+D;AAC/D,iDAA8C;AAC9C,6DAA4C;AAC5C,mEAA8D;AAC9D,qDAA6D;AAC7D,+BAA+B;AAI/B;;GAEG;AAEH,IAAa,gBA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AC;iBAC1C;aACF;iBAAM;gBACL,IAAI,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,EAAE,KAAK,EAAE,EAAC,OAAO,EAAE,sBAAsB,EAAC,CAAC,CAAC;aACnF;QACH,CAAC,CAAC;IACJ,CAAC;CACF,CAAA;AA9IY,gBAAgB;IAD5B,IAAA,eAAU,GAAE;6CAImB,oBAAe;GAHlC,gBAAgB,CA8I5B;AA9IY,4CAAgB","sourcesContent":["import {PlatformContext, PlatformHandler} from \"@tsed/common\";\nimport {ancestorsOf} from \"@tsed/core\";\nimport {Injectable, InjectorService, Provider} from \"@tsed/di\";\nimport {Unauthorized} from \"@tsed/exceptions\";\nimport Passport, {Strategy} from \"passport\";\nimport {PassportException} from \"../errors/PassportException\";\nimport {PROVIDER_TYPE_PROTOCOL} from \"../contants/constants\";\nimport {promisify} from \"util\";\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 constructor(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<any>) {\n const platformHandler = this.injector.get<PlatformHandler>(PlatformHandler)!;\n const middleware = 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 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"]}
|
|
@@ -16,7 +16,7 @@ let ProtocolsService = class ProtocolsService {
|
|
|
16
16
|
this.strategies = new Map();
|
|
17
17
|
}
|
|
18
18
|
getProtocols() {
|
|
19
|
-
return
|
|
19
|
+
return this.injector.getProviders(PROVIDER_TYPE_PROTOCOL);
|
|
20
20
|
}
|
|
21
21
|
getProtocolsNames() {
|
|
22
22
|
return Array.from(this.strategies.keys());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProtocolsService.js","sourceRoot":"","sources":["../../../src/services/ProtocolsService.ts"],"names":[],"mappings":";AAAA,OAAO,EAAkB,eAAe,EAAC,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AACvC,OAAO,EAAC,UAAU,EAAE,eAAe,EAAW,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,QAAQ,EAAE,EAAC,QAAQ,EAAC,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAC,sBAAsB,EAAC,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAC,SAAS,EAAC,MAAM,MAAM,CAAC;AAI/B;;GAEG;AAEH,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAG3B,YAAoB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;QAFpC,eAAU,GAA0B,IAAI,GAAG,EAAE,CAAC;IAEP,CAAC;IAE1C,YAAY;QACjB,OAAO,
|
|
1
|
+
{"version":3,"file":"ProtocolsService.js","sourceRoot":"","sources":["../../../src/services/ProtocolsService.ts"],"names":[],"mappings":";AAAA,OAAO,EAAkB,eAAe,EAAC,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AACvC,OAAO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C,CAAC,CAAC,CAAC,CAAC;gBAEjD,IAAI;oBACF,MAAM,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;oBAC3B,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;iBACzC;gBAAC,OAAO,GAAG,EAAE;oBACZ,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,EAAC,OAAO,EAAE,GAAG,CAAC,OAAO,EAAC,CAAC,CAAC;iBAC1C;aACF;iBAAM;gBACL,IAAI,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,EAAE,KAAK,EAAE,EAAC,OAAO,EAAE,sBAAsB,EAAC,CAAC,CAAC;aACnF;QACH,CAAC,CAAC;IACJ,CAAC;CACF,CAAA;AA9IY,gBAAgB;IAD5B,UAAU,EAAE;qCAImB,eAAe;GAHlC,gBAAgB,CA8I5B;SA9IY,gBAAgB","sourcesContent":["import {PlatformContext, PlatformHandler} from \"@tsed/common\";\nimport {ancestorsOf} from \"@tsed/core\";\nimport {Injectable, InjectorService, Provider} from \"@tsed/di\";\nimport {Unauthorized} from \"@tsed/exceptions\";\nimport Passport, {Strategy} from \"passport\";\nimport {PassportException} from \"../errors/PassportException\";\nimport {PROVIDER_TYPE_PROTOCOL} from \"../contants/constants\";\nimport {promisify} from \"util\";\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 constructor(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<any>) {\n const platformHandler = this.injector.get<PlatformHandler>(PlatformHandler)!;\n const middleware = 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 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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/passport",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.110.0",
|
|
4
4
|
"description": "Passport package for Ts.ED framework",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -22,30 +22,30 @@
|
|
|
22
22
|
"start": "ts-node src/index.ts"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"tslib": "2.
|
|
25
|
+
"tslib": "2.3.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@tsed/common": "6.
|
|
29
|
-
"@tsed/core": "6.
|
|
30
|
-
"@tsed/di": "6.
|
|
31
|
-
"@types/passport": "1.0.
|
|
32
|
-
"@types/passport-http": "0.3.
|
|
28
|
+
"@tsed/common": "6.110.0",
|
|
29
|
+
"@tsed/core": "6.110.0",
|
|
30
|
+
"@tsed/di": "6.110.0",
|
|
31
|
+
"@types/passport": "1.0.7",
|
|
32
|
+
"@types/passport-http": "0.3.9",
|
|
33
33
|
"@types/passport-local": "1.0.34",
|
|
34
34
|
"@types/passport-strategy": "0.2.35",
|
|
35
|
-
"passport": "0.
|
|
35
|
+
"passport": "0.5.2",
|
|
36
36
|
"passport-http": "0.3.0",
|
|
37
37
|
"passport-local": "1.0.0",
|
|
38
38
|
"passport-strategy": "1.0.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@tsed/common": "^6.
|
|
42
|
-
"@tsed/core": "^6.107.5",
|
|
43
|
-
"@tsed/di": "^6.107.5",
|
|
44
|
-
"@tsed/json-mapper": "^6.107.5",
|
|
45
|
-
"@tsed/logger": ">=6.1.0",
|
|
46
|
-
"@tsed/schema": "^6.107.5",
|
|
41
|
+
"@tsed/common": "^6.110.0",
|
|
47
42
|
"passport": ">=0.4.1"
|
|
48
43
|
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"@tsed/common": {
|
|
46
|
+
"optional": false
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
49
|
"repository": "https://github.com/tsedio/tsed",
|
|
50
50
|
"bugs": {
|
|
51
51
|
"url": "https://github.com/tsedio/tsed/issues"
|