@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
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Constant, Inject, Module, PlatformApplication, ProviderScope, Logger } from "@tsed/common";
|
|
3
3
|
import Passport from "passport";
|
|
4
|
-
import { PassportSerializerService } from "./services/PassportSerializerService";
|
|
5
|
-
import { ProtocolsService } from "./services/ProtocolsService";
|
|
4
|
+
import { PassportSerializerService } from "./services/PassportSerializerService.js";
|
|
5
|
+
import { ProtocolsService } from "./services/ProtocolsService.js";
|
|
6
6
|
/**
|
|
7
7
|
* @ignore
|
|
8
8
|
*/
|
|
9
9
|
let PassportModule = class PassportModule {
|
|
10
|
+
app;
|
|
11
|
+
protocolsService;
|
|
12
|
+
passportSerializer;
|
|
13
|
+
userProperty;
|
|
14
|
+
pauseStream;
|
|
15
|
+
disableSession;
|
|
16
|
+
platformName;
|
|
17
|
+
logger;
|
|
10
18
|
constructor(app, protocolsService, passportSerializer) {
|
|
11
19
|
this.app = app;
|
|
12
20
|
this.protocolsService = protocolsService;
|
|
13
21
|
this.passportSerializer = passportSerializer;
|
|
14
22
|
}
|
|
15
|
-
$onInit() {
|
|
23
|
+
async $onInit() {
|
|
16
24
|
Passport.serializeUser(this.passportSerializer.serialize.bind(this.passportSerializer));
|
|
17
25
|
Passport.deserializeUser(this.passportSerializer.deserialize.bind(this.passportSerializer));
|
|
18
|
-
this.protocolsService.getProtocols().
|
|
26
|
+
const promises = this.protocolsService.getProtocols().map((provider) => this.protocolsService.invoke(provider));
|
|
27
|
+
await Promise.all(promises);
|
|
19
28
|
return undefined;
|
|
20
29
|
}
|
|
21
30
|
$beforeRoutesInit() {
|
|
@@ -23,7 +32,7 @@ let PassportModule = class PassportModule {
|
|
|
23
32
|
switch (this.platformName) {
|
|
24
33
|
case "express":
|
|
25
34
|
this.app.use(Passport.initialize({ userProperty }));
|
|
26
|
-
this.app.use(Passport.session({ pauseStream }));
|
|
35
|
+
!this.disableSession && this.app.use(Passport.session({ pauseStream }));
|
|
27
36
|
return;
|
|
28
37
|
default:
|
|
29
38
|
this.logger.warn(`Platform "${this.platformName}" not supported by @tsed/passport`);
|
|
@@ -38,6 +47,10 @@ __decorate([
|
|
|
38
47
|
Constant("passport.pauseStream"),
|
|
39
48
|
__metadata("design:type", Boolean)
|
|
40
49
|
], PassportModule.prototype, "pauseStream", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
Constant("passport.disableSession", false),
|
|
52
|
+
__metadata("design:type", Boolean)
|
|
53
|
+
], PassportModule.prototype, "disableSession", void 0);
|
|
41
54
|
__decorate([
|
|
42
55
|
Constant("PLATFORM_NAME"),
|
|
43
56
|
__metadata("design:type", String)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PassportModule.js","sourceRoot":"","sources":["../../src/PassportModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAmB,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAU,mBAAmB,EAAY,aAAa,EAAE,MAAM,EAAC,MAAM,cAAc,CAAC;AACtI,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,yBAAyB,EAAC,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAC;AAE7D;;GAEG;AAIH,IAAa,cAAc,GAA3B,MAAa,cAAc;
|
|
1
|
+
{"version":3,"file":"PassportModule.js","sourceRoot":"","sources":["../../src/PassportModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAmB,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAU,mBAAmB,EAAY,a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AAC,UAAU,CAAC,EAAC,YAAY,EAAC,CAAC,CAAC,CAAC;gBAClD,CAAC,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAC,WAAW,EAAC,CAAC,CAAC,CAAC;gBAEtE,OAAO;YAET;gBACE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,YAAY,mCAAmC,CAAC,CAAC;SACvF;IACH,CAAC;CACF,CAAA;AA3CC;IADC,QAAQ,CAAC,uBAAuB,CAAC;;oDACb;AAGrB;IADC,QAAQ,CAAC,sBAAsB,CAAC;;mDACZ;AAGrB;IADC,QAAQ,CAAC,yBAAyB,EAAE,KAAK,CAAC;;sDACnB;AAGxB;IADC,QAAQ,CAAC,eAAe,CAAC;;oDACL;AAGrB;IADC,MAAM,EAAE;8BACD,MAAM;8CAAC;AAdJ,cAAc;IAH1B,MAAM,CAAC;QACN,KAAK,EAAE,aAAa,CAAC,SAAS;KAC/B,CAAC;qCAkBe,mBAAmB;QACN,gBAAgB;QACd,yBAAyB;GAnB5C,cAAc,CA6C1B;SA7CY,cAAc","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"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const PROVIDER_TYPE_PROTOCOL = "protocol";
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/contants/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG,UAAU,CAAC","sourcesContent":["export const PROVIDER_TYPE_PROTOCOL = \"protocol\";\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { UseAuth } from "@tsed/
|
|
2
|
-
import { PassportMiddleware } from "../middlewares/PassportMiddleware";
|
|
1
|
+
import { UseAuth } from "@tsed/platform-middlewares";
|
|
3
2
|
import { useDecorators } from "@tsed/core";
|
|
4
3
|
import { Security } from "@tsed/schema";
|
|
4
|
+
import { PassportMiddleware } from "../middlewares/PassportMiddleware.js";
|
|
5
5
|
export function Authenticate(protocol = "*", options = {}) {
|
|
6
6
|
return useDecorators(UseAuth(PassportMiddleware, {
|
|
7
7
|
protocol,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../../../src/decorators/authenticate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../../../src/decorators/authenticate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAC,kBAAkB,EAAC,MAAM,mCAAmC,CAAC;AAOrE,MAAM,UAAU,YAAY,CAAC,WAA8B,GAAG,EAAE,UAA+B,EAAE;IAC/F,OAAO,aAAa,CAClB,OAAO,CAAC,kBAAkB,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,QAAQ,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","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,7 +1,7 @@
|
|
|
1
|
-
import { UseAuth } from "@tsed/
|
|
2
|
-
import { PassportMiddleware } from "../middlewares/PassportMiddleware";
|
|
1
|
+
import { UseAuth } from "@tsed/platform-middlewares";
|
|
3
2
|
import { useDecorators } from "@tsed/core";
|
|
4
3
|
import { Security } from "@tsed/schema";
|
|
4
|
+
import { PassportMiddleware } from "../middlewares/PassportMiddleware.js";
|
|
5
5
|
export function Authorize(protocol = "*", options = {}) {
|
|
6
6
|
return useDecorators(UseAuth(PassportMiddleware, {
|
|
7
7
|
protocol,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../../src/decorators/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../../src/decorators/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAC,kBAAkB,EAAC,MAAM,mCAAmC,CAAC;AAOrE,MAAM,UAAU,SAAS,CAAC,WAA8B,GAAG,EAAE,UAA4B,EAAE;IACzF,OAAO,aAAa,CAClB,OAAO,CAAC,kBAAkB,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,QAAQ,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StoreSet, useDecorators } from "@tsed/core";
|
|
2
2
|
import { Configuration, Injectable } from "@tsed/di";
|
|
3
|
-
import { PROVIDER_TYPE_PROTOCOL } from "../contants";
|
|
3
|
+
import { PROVIDER_TYPE_PROTOCOL } from "../contants/constants.js";
|
|
4
4
|
/**
|
|
5
5
|
* Declare a new Protocol base on a Passport Strategy
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/decorators/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACnD,OAAO,EAAC,aAAa,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAEnD,OAAO,EAAC,sBAAsB,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/decorators/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACnD,OAAO,EAAC,aAAa,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAEnD,OAAO,EAAC,sBAAsB,EAAC,MAAM,uBAAuB,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAU,OAAoC;IACpE,OAAO,aAAa,CAClB,UAAU,CAAC;QACT,IAAI,EAAE,sBAAsB;KAC7B,CAAC,EACF,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,EAC7B,aAAa,CAAC;QACZ,QAAQ,EAAE;YACR,SAAS,EAAE;gBACT,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO;aACxB;SACF;KACF,CAAC,CACH,CAAC;AACJ,CAAC","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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserInfo.js","sourceRoot":"","sources":["../../../src/domain/UserInfo.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AAE9C,MAAM,OAAO,QAAQ;
|
|
1
|
+
{"version":3,"file":"UserInfo.js","sourceRoot":"","sources":["../../../src/domain/UserInfo.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AAE9C,MAAM,OAAO,QAAQ;IAEnB,EAAE,CAAS;IAIX,KAAK,CAAS;IAGd,QAAQ,CAAS;CAClB;AARC;IADC,QAAQ,EAAE;;oCACA;AAIX;IAFC,QAAQ,EAAE;IACV,MAAM,CAAC,OAAO,CAAC;;uCACF;AAGd;IADC,QAAQ,EAAE;;0CACM","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/esm/index.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./decorators/args";
|
|
7
|
-
|
|
8
|
-
export * from "./
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./
|
|
11
|
-
|
|
12
|
-
export * from "./
|
|
13
|
-
export * from "./
|
|
14
|
-
export * from "./
|
|
15
|
-
|
|
16
|
-
export * from "./
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./PassportModule.js";
|
|
5
|
+
export * from "./contants/constants.js";
|
|
6
|
+
export * from "./decorators/args.js";
|
|
7
|
+
export * from "./decorators/authenticate.js";
|
|
8
|
+
export * from "./decorators/authorize.js";
|
|
9
|
+
export * from "./decorators/protocol.js";
|
|
10
|
+
export * from "./domain/UserInfo.js";
|
|
11
|
+
export * from "./errors/PassportException.js";
|
|
12
|
+
export * from "./interfaces/BeforeInstall.js";
|
|
13
|
+
export * from "./interfaces/OnInstall.js";
|
|
14
|
+
export * from "./interfaces/OnVerify.js";
|
|
15
|
+
export * from "./interfaces/ProtocolMethods.js";
|
|
16
|
+
export * from "./interfaces/ProtocolOptions.js";
|
|
17
|
+
export * from "./interfaces/interfaces.js";
|
|
18
|
+
export * from "./middlewares/PassportMiddleware.js";
|
|
19
|
+
export * from "./services/PassportSerializerService.js";
|
|
20
|
+
export * from "./services/ProtocolsService.js";
|
|
21
|
+
export * from "./utils/getProtocolsFromRequest.js";
|
|
17
22
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,sCAAsC,CAAC;AACrD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC","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"]}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
var PassportMiddleware_1;
|
|
2
2
|
import { __decorate, __metadata, __param } from "tslib";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { Inject } from "@tsed/di";
|
|
4
|
+
import { Middleware } from "@tsed/platform-middlewares";
|
|
5
|
+
import { Context } from "@tsed/common";
|
|
6
|
+
import { ProtocolsService } from "../services/ProtocolsService.js";
|
|
7
|
+
import { getProtocolsFromRequest } from "../utils/getProtocolsFromRequest.js";
|
|
6
8
|
let PassportMiddleware = PassportMiddleware_1 = class PassportMiddleware {
|
|
9
|
+
protocolsService;
|
|
7
10
|
shouldSkip(ctx) {
|
|
8
11
|
const request = ctx.getRequest();
|
|
9
12
|
return request.user && request.isAuthenticated();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PassportMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PassportMiddleware.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"PassportMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PassportMiddleware.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CA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CAAC;CACF,CAAA;AAzBC;IADC,MAAM,CAAC,gBAAgB,CAAC;8BACP,gBAAgB;4DAAC;AAOnC;IAAW,WAAA,OAAO,EAAE,CAAA;;;;6CAiBnB;AA1BU,kBAAkB;IAD9B,UAAU,EAAE;GACA,kBAAkB,CA2B9B;SA3BY,kBAAkB","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"]}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Constant, Service } from "@tsed/di";
|
|
3
3
|
import { deserialize, serialize } from "@tsed/json-mapper";
|
|
4
|
-
import { UserInfo } from "../domain/UserInfo";
|
|
4
|
+
import { UserInfo } from "../domain/UserInfo.js";
|
|
5
5
|
/**
|
|
6
6
|
* @ignore
|
|
7
7
|
*/
|
|
8
8
|
let PassportSerializerService = class PassportSerializerService {
|
|
9
|
+
model;
|
|
9
10
|
serialize(user, done) {
|
|
10
11
|
try {
|
|
11
12
|
const obj = serialize(user, { type: this.model });
|
|
12
13
|
// remove password from serialized object
|
|
13
|
-
|
|
14
|
+
obj.password = undefined;
|
|
14
15
|
done(null, JSON.stringify(obj));
|
|
15
16
|
}
|
|
16
17
|
catch (er) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PassportSerializerService.js","sourceRoot":"","sources":["../../../src/services/PassportSerializerService.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,QAAQ,EAAE,OAAO,EAAC,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAC,WAAW,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAE5C;;GAEG;AAEH,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;
|
|
1
|
+
{"version":3,"file":"PassportSerializerService.js","sourceRoot":"","sources":["../../../src/services/PassportSerializerService.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,QAAQ,EAAE,OAAO,EAAC,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAC,WAAW,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAE5C;;GAEG;AAEH,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IAE5B,KAAK,CAA2B;IAExC,SAAS,CAAC,IAAc,EAAE,IAAS;QACjC,IAAI;YACF,MAAM,GAAG,GAAG,SAAS,CAAC,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,WAAW,CAAC,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,QAAQ,CAAC,wBAAwB,EAAE,QAAQ,CAAC;;wDACL;AAF7B,yBAAyB;IADrC,OAAO,EAAE;GACG,yBAAyB,CA2BrC;SA3BY,yBAAyB","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"]}
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { PlatformHandler } from "@tsed/common";
|
|
3
3
|
import { ancestorsOf } from "@tsed/core";
|
|
4
|
-
import { Injectable, InjectorService } from "@tsed/di";
|
|
4
|
+
import { Inject, Injectable, InjectorService } from "@tsed/di";
|
|
5
5
|
import { Unauthorized } from "@tsed/exceptions";
|
|
6
6
|
import Passport, { Strategy } from "passport";
|
|
7
|
-
import { PassportException } from "../errors/PassportException";
|
|
8
|
-
import { PROVIDER_TYPE_PROTOCOL } from "../contants";
|
|
9
7
|
import { promisify } from "util";
|
|
8
|
+
import { PROVIDER_TYPE_PROTOCOL } from "../contants/constants.js";
|
|
9
|
+
import { PassportException } from "../errors/PassportException.js";
|
|
10
10
|
/**
|
|
11
11
|
* @ignore
|
|
12
12
|
*/
|
|
13
13
|
let ProtocolsService = class ProtocolsService {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
14
|
+
strategies = new Map();
|
|
15
|
+
platformHandler;
|
|
16
|
+
injector;
|
|
18
17
|
getProtocols() {
|
|
19
|
-
return
|
|
18
|
+
return this.injector.getProviders(PROVIDER_TYPE_PROTOCOL);
|
|
20
19
|
}
|
|
21
20
|
getProtocolsNames() {
|
|
22
21
|
return Array.from(this.strategies.keys());
|
|
@@ -25,14 +24,17 @@ let ProtocolsService = class ProtocolsService {
|
|
|
25
24
|
* Invoke provider and bind it to passport.
|
|
26
25
|
* @param provider
|
|
27
26
|
*/
|
|
28
|
-
invoke(provider) {
|
|
29
|
-
|
|
27
|
+
async invoke(provider) {
|
|
28
|
+
let { name, useStrategy: strategy, settings } = this.getOptions(provider);
|
|
30
29
|
const protocol = this.injector.get(provider.provide);
|
|
30
|
+
if (protocol.$beforeInstall) {
|
|
31
|
+
settings = (await protocol.$beforeInstall(settings)) || settings;
|
|
32
|
+
}
|
|
31
33
|
const instance = new strategy(settings, this.createHandler(provider));
|
|
32
34
|
this.strategies.set(name, instance);
|
|
33
35
|
Passport.use(name, instance);
|
|
34
36
|
if (protocol.$onInstall) {
|
|
35
|
-
protocol.$onInstall(instance);
|
|
37
|
+
await protocol.$onInstall(instance);
|
|
36
38
|
}
|
|
37
39
|
protocol.$strategy = instance;
|
|
38
40
|
return protocol;
|
|
@@ -106,24 +108,35 @@ let ProtocolsService = class ProtocolsService {
|
|
|
106
108
|
* @private
|
|
107
109
|
*/
|
|
108
110
|
createHandler(provider) {
|
|
109
|
-
const
|
|
110
|
-
const middleware = platformHandler.createCustomHandler(provider, "$onVerify");
|
|
111
|
+
const middleware = this.platformHandler.createCustomHandler(provider, "$onVerify");
|
|
111
112
|
return async (req, ...args) => {
|
|
112
113
|
const done = args[args.length - 1];
|
|
113
|
-
req.$ctx
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
if (req.$ctx) {
|
|
115
|
+
req.$ctx.set("PROTOCOL_ARGS", args.slice(0, -1));
|
|
116
|
+
try {
|
|
117
|
+
await middleware(req.$ctx);
|
|
118
|
+
done(null, ...[].concat(req.$ctx.data));
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
done(err, false, { message: err.message });
|
|
122
|
+
}
|
|
117
123
|
}
|
|
118
|
-
|
|
119
|
-
done(
|
|
124
|
+
else {
|
|
125
|
+
done(new Error("Headers already sent"), false, { message: "Headers already sent" });
|
|
120
126
|
}
|
|
121
127
|
};
|
|
122
128
|
}
|
|
123
129
|
};
|
|
130
|
+
__decorate([
|
|
131
|
+
Inject(),
|
|
132
|
+
__metadata("design:type", PlatformHandler)
|
|
133
|
+
], ProtocolsService.prototype, "platformHandler", void 0);
|
|
134
|
+
__decorate([
|
|
135
|
+
Inject(),
|
|
136
|
+
__metadata("design:type", InjectorService)
|
|
137
|
+
], ProtocolsService.prototype, "injector", void 0);
|
|
124
138
|
ProtocolsService = __decorate([
|
|
125
|
-
Injectable()
|
|
126
|
-
__metadata("design:paramtypes", [InjectorService])
|
|
139
|
+
Injectable()
|
|
127
140
|
], ProtocolsService);
|
|
128
141
|
export { ProtocolsService };
|
|
129
142
|
//# sourceMappingURL=ProtocolsService.js.map
|
|
@@ -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,U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I,GAAG,CAAC,IAAI,EAAE;gBACZ,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;gBAEjD,IAAI;oBACF,MAAM,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;oBAE3B,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;AA9IC;IADC,MAAM,EAAE;8BACkB,eAAe;yDAAC;AAG3C;IADC,MAAM,EAAE;8BACS,eAAe;kDAAC;AAPvB,gBAAgB;IAD5B,UAAU,EAAE;GACA,gBAAgB,CAkJ5B;SAlJY,gBAAgB","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"]}
|
|
@@ -10,9 +10,10 @@ export declare class PassportModule implements OnInit, BeforeRoutesInit {
|
|
|
10
10
|
private passportSerializer;
|
|
11
11
|
userProperty: string;
|
|
12
12
|
pauseStream: boolean;
|
|
13
|
+
disableSession: boolean;
|
|
13
14
|
platformName: string;
|
|
14
15
|
logger: Logger;
|
|
15
16
|
constructor(app: PlatformApplication, protocolsService: ProtocolsService, passportSerializer: PassportSerializerService);
|
|
16
|
-
$onInit(): Promise<any
|
|
17
|
+
$onInit(): Promise<any>;
|
|
17
18
|
$beforeRoutesInit(): void | Promise<any>;
|
|
18
19
|
}
|
|
File without changes
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./PassportModule";
|
|
5
|
+
export * from "./contants/constants";
|
|
6
|
+
export * from "./decorators/args";
|
|
2
7
|
export * from "./decorators/authenticate";
|
|
3
8
|
export * from "./decorators/authorize";
|
|
4
9
|
export * from "./decorators/protocol";
|
|
5
|
-
export * from "./decorators/args";
|
|
6
|
-
export * from "./interfaces";
|
|
7
10
|
export * from "./domain/UserInfo";
|
|
8
11
|
export * from "./errors/PassportException";
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./
|
|
11
|
-
export * from "./
|
|
12
|
+
export * from "./interfaces/BeforeInstall";
|
|
13
|
+
export * from "./interfaces/OnInstall";
|
|
14
|
+
export * from "./interfaces/OnVerify";
|
|
15
|
+
export * from "./interfaces/ProtocolMethods";
|
|
16
|
+
export * from "./interfaces/ProtocolOptions";
|
|
17
|
+
export * from "./interfaces/interfaces";
|
|
12
18
|
export * from "./middlewares/PassportMiddleware";
|
|
19
|
+
export * from "./services/PassportSerializerService";
|
|
20
|
+
export * from "./services/ProtocolsService";
|
|
21
|
+
export * from "./utils/getProtocolsFromRequest";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
|
+
import { PassportStatic } from "passport";
|
|
2
3
|
import { ProtocolOptions } from "./ProtocolOptions";
|
|
3
4
|
declare global {
|
|
4
5
|
namespace TsED {
|
|
@@ -6,7 +7,9 @@ declare global {
|
|
|
6
7
|
passport: {
|
|
7
8
|
userProperty?: string;
|
|
8
9
|
pauseStream?: string;
|
|
10
|
+
disableSession?: boolean;
|
|
9
11
|
userInfoModel?: Type<any> | false;
|
|
12
|
+
module?: PassportStatic;
|
|
10
13
|
protocols?: {
|
|
11
14
|
[protocolName: string]: Partial<ProtocolOptions>;
|
|
12
15
|
};
|
|
@@ -14,7 +17,3 @@ declare global {
|
|
|
14
17
|
}
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
|
-
export * from "./ProtocolOptions";
|
|
18
|
-
export * from "./IProtocol";
|
|
19
|
-
export * from "./OnInstall";
|
|
20
|
-
export * from "./OnVerify";
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { PlatformContext } from "@tsed/common";
|
|
2
|
-
import {
|
|
1
|
+
import { PlatformContext, PlatformHandler } from "@tsed/common";
|
|
2
|
+
import { Provider } from "@tsed/di";
|
|
3
3
|
import { Strategy } from "passport";
|
|
4
|
+
import type { ProtocolMethods } from "../interfaces/ProtocolMethods";
|
|
4
5
|
/**
|
|
5
6
|
* @ignore
|
|
6
7
|
*/
|
|
7
8
|
export declare class ProtocolsService {
|
|
8
|
-
private injector;
|
|
9
9
|
readonly strategies: Map<string, Strategy>;
|
|
10
|
-
|
|
10
|
+
protected platformHandler: PlatformHandler;
|
|
11
|
+
private injector;
|
|
11
12
|
getProtocols(): Provider[];
|
|
12
13
|
getProtocolsNames(): string[];
|
|
13
14
|
/**
|
|
14
15
|
* Invoke provider and bind it to passport.
|
|
15
16
|
* @param provider
|
|
16
17
|
*/
|
|
17
|
-
invoke(provider: Provider): any
|
|
18
|
+
invoke(provider: Provider): Promise<ProtocolMethods<any> & Record<string, any>>;
|
|
18
19
|
/**
|
|
19
20
|
* Call authenticate passport method.
|
|
20
21
|
* @param protocols
|