@tsed/passport 7.0.0-alpha.1 → 7.0.0-beta.10
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/{PassportModule.js → cjs/PassportModule.js} +13 -8
- package/lib/cjs/PassportModule.js.map +1 -0
- package/lib/{contants/index.js → cjs/contants/constants.js} +1 -1
- package/lib/cjs/contants/constants.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/args.js +2 -2
- package/lib/cjs/decorators/args.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/authenticate.js +4 -4
- package/lib/cjs/decorators/authenticate.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/authorize.js +4 -4
- package/lib/cjs/decorators/authorize.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/protocol.js +4 -4
- package/lib/cjs/decorators/protocol.js.map +1 -0
- package/lib/{domain → cjs/domain}/UserInfo.js +4 -4
- package/lib/cjs/domain/UserInfo.js.map +1 -0
- package/lib/{errors → cjs/errors}/PassportException.js +0 -0
- package/lib/cjs/errors/PassportException.js.map +1 -0
- package/lib/{index.js → cjs/index.js} +15 -10
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/interfaces/BeforeInstall.js +3 -0
- package/lib/cjs/interfaces/BeforeInstall.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/OnInstall.js +0 -0
- package/lib/cjs/interfaces/OnInstall.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/OnVerify.js +0 -0
- package/lib/cjs/interfaces/OnVerify.js.map +1 -0
- package/lib/cjs/interfaces/ProtocolMethods.js +3 -0
- package/lib/cjs/interfaces/ProtocolMethods.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/ProtocolOptions.js +0 -0
- package/lib/cjs/interfaces/ProtocolOptions.js.map +1 -0
- package/lib/{interfaces/IProtocol.js → cjs/interfaces/interfaces.js} +1 -1
- package/lib/cjs/interfaces/interfaces.js.map +1 -0
- package/lib/{middlewares → cjs/middlewares}/PassportMiddleware.js +6 -4
- package/lib/cjs/middlewares/PassportMiddleware.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/{services → cjs/services}/PassportSerializerService.js +4 -4
- package/lib/cjs/services/PassportSerializerService.js.map +1 -0
- package/lib/{services → cjs/services}/ProtocolsService.js +22 -14
- package/lib/cjs/services/ProtocolsService.js.map +1 -0
- package/lib/{utils → cjs/utils}/getProtocolsFromRequest.js +1 -1
- package/lib/cjs/utils/getProtocolsFromRequest.js.map +1 -0
- package/lib/esm/PassportModule.js +63 -0
- package/lib/esm/PassportModule.js.map +1 -0
- package/lib/esm/contants/constants.js +2 -0
- package/lib/esm/contants/constants.js.map +1 -0
- package/lib/esm/decorators/args.js +13 -0
- package/lib/esm/decorators/args.js.map +1 -0
- package/lib/esm/decorators/authenticate.js +15 -0
- package/lib/esm/decorators/authenticate.js.map +1 -0
- package/lib/esm/decorators/authorize.js +15 -0
- package/lib/esm/decorators/authorize.js.map +1 -0
- package/lib/esm/decorators/protocol.js +21 -0
- package/lib/esm/decorators/protocol.js.map +1 -0
- package/lib/esm/domain/UserInfo.js +18 -0
- package/lib/esm/domain/UserInfo.js.map +1 -0
- package/lib/esm/errors/PassportException.js +8 -0
- package/lib/esm/errors/PassportException.js.map +1 -0
- package/lib/esm/index.js +22 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces/BeforeInstall.js +2 -0
- package/lib/esm/interfaces/BeforeInstall.js.map +1 -0
- package/lib/esm/interfaces/OnInstall.js +2 -0
- package/lib/esm/interfaces/OnInstall.js.map +1 -0
- package/lib/esm/interfaces/OnVerify.js +2 -0
- package/lib/esm/interfaces/OnVerify.js.map +1 -0
- package/lib/esm/interfaces/ProtocolMethods.js +2 -0
- package/lib/esm/interfaces/ProtocolMethods.js.map +1 -0
- package/lib/esm/interfaces/ProtocolOptions.js +2 -0
- package/lib/esm/interfaces/ProtocolOptions.js.map +1 -0
- package/lib/esm/interfaces/interfaces.js +2 -0
- package/lib/esm/interfaces/interfaces.js.map +1 -0
- package/lib/esm/middlewares/PassportMiddleware.js +43 -0
- package/lib/esm/middlewares/PassportMiddleware.js.map +1 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/services/PassportSerializerService.js +39 -0
- package/lib/esm/services/PassportSerializerService.js.map +1 -0
- package/lib/esm/services/ProtocolsService.js +137 -0
- package/lib/esm/services/ProtocolsService.js.map +1 -0
- package/lib/esm/utils/getProtocolsFromRequest.js +32 -0
- package/lib/esm/utils/getProtocolsFromRequest.js.map +1 -0
- package/lib/{PassportModule.d.ts → types/PassportModule.d.ts} +2 -1
- package/lib/{contants/index.d.ts → types/contants/constants.d.ts} +0 -0
- package/lib/{decorators → types/decorators}/args.d.ts +0 -0
- package/lib/{decorators → types/decorators}/authenticate.d.ts +0 -0
- package/lib/{decorators → types/decorators}/authorize.d.ts +0 -0
- package/lib/{decorators → types/decorators}/protocol.d.ts +0 -0
- package/lib/{domain → types/domain}/UserInfo.d.ts +0 -0
- package/lib/{errors → types/errors}/PassportException.d.ts +0 -0
- package/lib/types/index.d.ts +21 -0
- package/lib/types/interfaces/BeforeInstall.d.ts +3 -0
- package/lib/{interfaces → types/interfaces}/OnInstall.d.ts +1 -1
- package/lib/{interfaces → types/interfaces}/OnVerify.d.ts +0 -0
- package/lib/types/interfaces/ProtocolMethods.d.ts +5 -0
- package/lib/{interfaces → types/interfaces}/ProtocolOptions.d.ts +2 -2
- package/lib/{interfaces/index.d.ts → types/interfaces/interfaces.d.ts} +3 -4
- package/lib/{middlewares → types/middlewares}/PassportMiddleware.d.ts +0 -0
- package/lib/{services → types/services}/PassportSerializerService.d.ts +0 -0
- package/lib/{services → types/services}/ProtocolsService.d.ts +2 -1
- package/lib/{utils → types/utils}/getProtocolsFromRequest.d.ts +0 -0
- package/package.json +32 -28
- package/readme.md +15 -17
- package/tsconfig.compile.esm.json +12 -0
- package/lib/PassportModule.js.map +0 -1
- package/lib/contants/index.js.map +0 -1
- package/lib/decorators/args.js.map +0 -1
- package/lib/decorators/authenticate.js.map +0 -1
- package/lib/decorators/authorize.js.map +0 -1
- package/lib/decorators/protocol.js.map +0 -1
- package/lib/domain/UserInfo.js.map +0 -1
- package/lib/errors/PassportException.js.map +0 -1
- package/lib/index.d.ts +0 -12
- package/lib/index.js.map +0 -1
- package/lib/interfaces/IProtocol.d.ts +0 -4
- package/lib/interfaces/IProtocol.js.map +0 -1
- package/lib/interfaces/OnInstall.js.map +0 -1
- package/lib/interfaces/OnVerify.js.map +0 -1
- package/lib/interfaces/ProtocolOptions.js.map +0 -1
- package/lib/interfaces/index.js +0 -8
- package/lib/interfaces/index.js.map +0 -1
- package/lib/middlewares/PassportMiddleware.js.map +0 -1
- package/lib/services/PassportSerializerService.js.map +0 -1
- package/lib/services/ProtocolsService.js.map +0 -1
- package/lib/utils/getProtocolsFromRequest.js.map +0 -1
|
@@ -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"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Context } from "@tsed/common";
|
|
2
|
+
import { useDecorators } from "@tsed/core";
|
|
3
|
+
/**
|
|
4
|
+
* Inject args resolve by the passport strategy on verify method.
|
|
5
|
+
* @decorator
|
|
6
|
+
*/
|
|
7
|
+
export function Args() {
|
|
8
|
+
return useDecorators(Context("PROTOCOL_ARGS"));
|
|
9
|
+
}
|
|
10
|
+
export function Arg(index) {
|
|
11
|
+
return useDecorators(Context(`PROTOCOL_ARGS.${index}`));
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.js","sourceRoot":"","sources":["../../../src/decorators/args.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AACrC,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AAEzC;;;GAGG;AACH,MAAM,UAAU,IAAI;IAClB,OAAO,aAAa,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,KAAa;IAC/B,OAAO,aAAa,CAAC,OAAO,CAAC,iBAAiB,KAAK,EAAE,CAAC,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import {Context} from \"@tsed/common\";\nimport {useDecorators} from \"@tsed/core\";\n\n/**\n * Inject args resolve by the passport strategy on verify method.\n * @decorator\n */\nexport function Args() {\n return useDecorators(Context(\"PROTOCOL_ARGS\"));\n}\n\nexport function Arg(index: number) {\n return useDecorators(Context(`PROTOCOL_ARGS.${index}`));\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { UseAuth } from "@tsed/platform-middlewares";
|
|
2
|
+
import { useDecorators } from "@tsed/core";
|
|
3
|
+
import { Security } from "@tsed/schema";
|
|
4
|
+
import { PassportMiddleware } from "../middlewares/PassportMiddleware.js";
|
|
5
|
+
export function Authenticate(protocol = "*", options = {}) {
|
|
6
|
+
return useDecorators(UseAuth(PassportMiddleware, {
|
|
7
|
+
protocol,
|
|
8
|
+
method: "authenticate",
|
|
9
|
+
originalUrl: options.originalUrl === undefined ? true : options.originalUrl,
|
|
10
|
+
options
|
|
11
|
+
}), ...Object.entries(options.security || {}).map(([key, value]) => {
|
|
12
|
+
return Security(key, ...value);
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=authenticate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { UseAuth } from "@tsed/platform-middlewares";
|
|
2
|
+
import { useDecorators } from "@tsed/core";
|
|
3
|
+
import { Security } from "@tsed/schema";
|
|
4
|
+
import { PassportMiddleware } from "../middlewares/PassportMiddleware.js";
|
|
5
|
+
export function Authorize(protocol = "*", options = {}) {
|
|
6
|
+
return useDecorators(UseAuth(PassportMiddleware, {
|
|
7
|
+
protocol,
|
|
8
|
+
method: "authorize",
|
|
9
|
+
originalUrl: options.originalUrl === undefined ? true : options.originalUrl,
|
|
10
|
+
options
|
|
11
|
+
}), ...Object.entries(options.security || {}).map(([key, value]) => {
|
|
12
|
+
return Security(key, ...value);
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=authorize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { StoreSet, useDecorators } from "@tsed/core";
|
|
2
|
+
import { Configuration, Injectable } from "@tsed/di";
|
|
3
|
+
import { PROVIDER_TYPE_PROTOCOL } from "../contants/constants.js";
|
|
4
|
+
/**
|
|
5
|
+
* Declare a new Protocol base on a Passport Strategy
|
|
6
|
+
*
|
|
7
|
+
* @decorator
|
|
8
|
+
* @class
|
|
9
|
+
*/
|
|
10
|
+
export function Protocol(options) {
|
|
11
|
+
return useDecorators(Injectable({
|
|
12
|
+
type: PROVIDER_TYPE_PROTOCOL
|
|
13
|
+
}), StoreSet("protocol", options), Configuration({
|
|
14
|
+
passport: {
|
|
15
|
+
protocols: {
|
|
16
|
+
[options.name]: options
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +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,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"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Format, Property } from "@tsed/schema";
|
|
3
|
+
export class UserInfo {
|
|
4
|
+
}
|
|
5
|
+
__decorate([
|
|
6
|
+
Property(),
|
|
7
|
+
__metadata("design:type", String)
|
|
8
|
+
], UserInfo.prototype, "id", void 0);
|
|
9
|
+
__decorate([
|
|
10
|
+
Property(),
|
|
11
|
+
Format("email"),
|
|
12
|
+
__metadata("design:type", String)
|
|
13
|
+
], UserInfo.prototype, "email", void 0);
|
|
14
|
+
__decorate([
|
|
15
|
+
Property(),
|
|
16
|
+
__metadata("design:type", String)
|
|
17
|
+
], UserInfo.prototype, "password", void 0);
|
|
18
|
+
//# sourceMappingURL=UserInfo.js.map
|
|
@@ -0,0 +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;CAUpB;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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PassportException.js","sourceRoot":"","sources":["../../../src/errors/PassportException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,kBAAkB,CAAC;AAE3C,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAC9C,YAAY,KAAU;QACpB,KAAK,CAAC,KAAK,CAAC,MAAM,IAAI,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC;IACtC,CAAC;CACF","sourcesContent":["import {Exception} from \"@tsed/exceptions\";\n\nexport class PassportException extends Exception {\n constructor(error: any) {\n super(error.status || 500, error.message);\n this.name = error.name || this.name;\n }\n}\n"]}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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";
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -0,0 +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 | Promise<void>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OnVerify.js","sourceRoot":"","sources":["../../../src/interfaces/OnVerify.ts"],"names":[],"mappings":"","sourcesContent":["export interface OnVerify {\n $onVerify(...args: any[]): Promise<any | any[]> | any | any[];\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"]}
|
|
@@ -0,0 +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<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"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var PassportMiddleware_1;
|
|
2
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
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";
|
|
8
|
+
let PassportMiddleware = PassportMiddleware_1 = class PassportMiddleware {
|
|
9
|
+
shouldSkip(ctx) {
|
|
10
|
+
const request = ctx.getRequest();
|
|
11
|
+
return request.user && request.isAuthenticated();
|
|
12
|
+
}
|
|
13
|
+
async use(ctx) {
|
|
14
|
+
const endpoint = ctx.endpoint;
|
|
15
|
+
const request = ctx.getRequest();
|
|
16
|
+
if (this.shouldSkip(ctx)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const { options, protocol, method, originalUrl = true } = endpoint.store.get(PassportMiddleware_1);
|
|
20
|
+
const protocols = getProtocolsFromRequest(request, protocol, this.protocolsService.getProtocolsNames());
|
|
21
|
+
if (originalUrl) {
|
|
22
|
+
request.url = request.originalUrl;
|
|
23
|
+
}
|
|
24
|
+
await (method === "authenticate"
|
|
25
|
+
? this.protocolsService.authenticate(protocols, options, ctx)
|
|
26
|
+
: this.protocolsService.authorize(protocols, options, ctx));
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
__decorate([
|
|
30
|
+
Inject(ProtocolsService),
|
|
31
|
+
__metadata("design:type", ProtocolsService)
|
|
32
|
+
], PassportMiddleware.prototype, "protocolsService", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
__param(0, Context()),
|
|
35
|
+
__metadata("design:type", Function),
|
|
36
|
+
__metadata("design:paramtypes", [Object]),
|
|
37
|
+
__metadata("design:returntype", Promise)
|
|
38
|
+
], PassportMiddleware.prototype, "use", null);
|
|
39
|
+
PassportMiddleware = PassportMiddleware_1 = __decorate([
|
|
40
|
+
Middleware()
|
|
41
|
+
], PassportMiddleware);
|
|
42
|
+
export { PassportMiddleware };
|
|
43
|
+
//# sourceMappingURL=PassportMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PassportMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PassportMiddleware.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,UAAU,EAAC,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AACrC,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAC,uBAAuB,EAAC,MAAM,kCAAkC,CAAC;AAGzE,IAAa,kBAAkB,0BAA/B,MAAa,kBAAkB;IAI7B,UAAU,CAAC,GAAY;QACrB,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC;QACjC,OAAO,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,GAAG,CAAY,GAAY;QAC/B,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;QAC9B,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC;QAEjC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YACxB,OAAO;SACR;QACD,MAAM,EAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI,EAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,oBAAkB,CAAC,CAAC;QAC/F,MAAM,SAAS,GAAG,uBAAuB,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,CAAC,CAAC;QAExG,IAAI,WAAW,EAAE;YACf,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC;SACnC;QAED,MAAM,CAAC,MAAM,KAAK,cAAc;YAC9B,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,CAAC;YAC7D,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAChE,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"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Constant, Service } from "@tsed/di";
|
|
3
|
+
import { deserialize, serialize } from "@tsed/json-mapper";
|
|
4
|
+
import { UserInfo } from "../domain/UserInfo.js";
|
|
5
|
+
/**
|
|
6
|
+
* @ignore
|
|
7
|
+
*/
|
|
8
|
+
let PassportSerializerService = class PassportSerializerService {
|
|
9
|
+
serialize(user, done) {
|
|
10
|
+
try {
|
|
11
|
+
const obj = serialize(user, { type: this.model });
|
|
12
|
+
// remove password from serialized object
|
|
13
|
+
delete obj.password;
|
|
14
|
+
done(null, JSON.stringify(obj));
|
|
15
|
+
}
|
|
16
|
+
catch (er) {
|
|
17
|
+
// istanbul ignore next
|
|
18
|
+
done(er);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
deserialize(obj, done) {
|
|
22
|
+
try {
|
|
23
|
+
const user = deserialize(JSON.parse(obj), { type: this.model });
|
|
24
|
+
done(null, user);
|
|
25
|
+
}
|
|
26
|
+
catch (er) {
|
|
27
|
+
done(er);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
__decorate([
|
|
32
|
+
Constant("passport.userInfoModel", UserInfo),
|
|
33
|
+
__metadata("design:type", Object)
|
|
34
|
+
], PassportSerializerService.prototype, "model", void 0);
|
|
35
|
+
PassportSerializerService = __decorate([
|
|
36
|
+
Service()
|
|
37
|
+
], PassportSerializerService);
|
|
38
|
+
export { PassportSerializerService };
|
|
39
|
+
//# sourceMappingURL=PassportSerializerService.js.map
|
|
@@ -0,0 +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;IAIpC,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,OAAO,GAAG,CAAC,QAAQ,CAAC;YAEpB,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 delete obj.password;\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"]}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { PlatformHandler } from "@tsed/common";
|
|
3
|
+
import { ancestorsOf } from "@tsed/core";
|
|
4
|
+
import { Injectable, InjectorService } from "@tsed/di";
|
|
5
|
+
import { Unauthorized } from "@tsed/exceptions";
|
|
6
|
+
import Passport, { Strategy } from "passport";
|
|
7
|
+
import { PassportException } from "../errors/PassportException.js";
|
|
8
|
+
import { PROVIDER_TYPE_PROTOCOL } from "../contants/constants.js";
|
|
9
|
+
import { promisify } from "util";
|
|
10
|
+
/**
|
|
11
|
+
* @ignore
|
|
12
|
+
*/
|
|
13
|
+
let ProtocolsService = class ProtocolsService {
|
|
14
|
+
constructor(injector) {
|
|
15
|
+
this.injector = injector;
|
|
16
|
+
this.strategies = new Map();
|
|
17
|
+
}
|
|
18
|
+
getProtocols() {
|
|
19
|
+
return this.injector.getProviders(PROVIDER_TYPE_PROTOCOL);
|
|
20
|
+
}
|
|
21
|
+
getProtocolsNames() {
|
|
22
|
+
return Array.from(this.strategies.keys());
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Invoke provider and bind it to passport.
|
|
26
|
+
* @param provider
|
|
27
|
+
*/
|
|
28
|
+
async invoke(provider) {
|
|
29
|
+
let { name, useStrategy: strategy, settings } = this.getOptions(provider);
|
|
30
|
+
const protocol = this.injector.get(provider.provide);
|
|
31
|
+
if (protocol.$beforeInstall) {
|
|
32
|
+
settings = (await protocol.$beforeInstall(settings)) || settings;
|
|
33
|
+
}
|
|
34
|
+
const instance = new strategy(settings, this.createHandler(provider));
|
|
35
|
+
this.strategies.set(name, instance);
|
|
36
|
+
Passport.use(name, instance);
|
|
37
|
+
if (protocol.$onInstall) {
|
|
38
|
+
await protocol.$onInstall(instance);
|
|
39
|
+
}
|
|
40
|
+
protocol.$strategy = instance;
|
|
41
|
+
return protocol;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Call authenticate passport method.
|
|
45
|
+
* @param protocols
|
|
46
|
+
* @param options
|
|
47
|
+
* @param ctx
|
|
48
|
+
*/
|
|
49
|
+
async authenticate(protocols, options, ctx) {
|
|
50
|
+
return this.call("authenticate", protocols, options, ctx);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Call authorize passport method.
|
|
54
|
+
* @param protocols
|
|
55
|
+
* @param options
|
|
56
|
+
* @param ctx
|
|
57
|
+
*/
|
|
58
|
+
async authorize(protocols, options, ctx) {
|
|
59
|
+
return this.call("authorize", protocols, options, ctx);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Call passport authenticate or authorize depending on the chosen method.
|
|
63
|
+
* @param method
|
|
64
|
+
* @param protocols
|
|
65
|
+
* @param options
|
|
66
|
+
* @param ctx
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
async call(method, protocols, options, ctx) {
|
|
70
|
+
const request = ctx.getRequest();
|
|
71
|
+
const response = ctx.getResponse();
|
|
72
|
+
protocols = [].concat(protocols);
|
|
73
|
+
if (protocols.length === 0) {
|
|
74
|
+
throw new Unauthorized("Not authorized");
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
options.failWithError = true;
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
const fn = promisify(Passport[method](protocols.length === 1 ? protocols[0] : protocols, options));
|
|
80
|
+
await fn(request, response);
|
|
81
|
+
}
|
|
82
|
+
catch (er) {
|
|
83
|
+
if (!ancestorsOf(er).includes(Error)) {
|
|
84
|
+
throw new PassportException(er);
|
|
85
|
+
}
|
|
86
|
+
throw er;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Create strategy options based on decorator metadata and global configuration
|
|
91
|
+
* @param provider
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
getOptions(provider) {
|
|
95
|
+
const { name } = provider.store.get("protocol");
|
|
96
|
+
const { useStrategy = Strategy, settings = {} } = this.injector.settings.get(`passport.protocols.${name}`) || {};
|
|
97
|
+
return {
|
|
98
|
+
name,
|
|
99
|
+
useStrategy,
|
|
100
|
+
settings: {
|
|
101
|
+
...settings,
|
|
102
|
+
passReqToCallback: true
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Create the verifier handler for passport
|
|
108
|
+
* @param provider
|
|
109
|
+
* @private
|
|
110
|
+
*/
|
|
111
|
+
createHandler(provider) {
|
|
112
|
+
const platformHandler = this.injector.get(PlatformHandler);
|
|
113
|
+
const middleware = platformHandler.createCustomHandler(provider, "$onVerify");
|
|
114
|
+
return async (req, ...args) => {
|
|
115
|
+
const done = args[args.length - 1];
|
|
116
|
+
if (req.$ctx) {
|
|
117
|
+
req.$ctx.set("PROTOCOL_ARGS", args.slice(0, -1));
|
|
118
|
+
try {
|
|
119
|
+
await middleware(req.$ctx);
|
|
120
|
+
done(null, ...[].concat(req.$ctx.data));
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
done(err, false, { message: err.message });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
done(new Error("Headers already sent"), false, { message: "Headers already sent" });
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
ProtocolsService = __decorate([
|
|
133
|
+
Injectable(),
|
|
134
|
+
__metadata("design:paramtypes", [InjectorService])
|
|
135
|
+
], ProtocolsService);
|
|
136
|
+
export { ProtocolsService };
|
|
137
|
+
//# sourceMappingURL=ProtocolsService.js.map
|
|
@@ -0,0 +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,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,sBAAsB,CAAC,CAAC;IAC5D,CAAC;IAEM,iBAAiB;QACtB,O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":["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"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isArray } from "@tsed/core";
|
|
2
|
+
/**
|
|
3
|
+
* @ignore
|
|
4
|
+
*/
|
|
5
|
+
function getProtocolName(req) {
|
|
6
|
+
const { query = {}, params = {}, body = {} } = req;
|
|
7
|
+
return params.protocol || query.protocol || body.protocol;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @ignore
|
|
11
|
+
*/
|
|
12
|
+
export function getProtocolsFromRequest(req, protocol, defaultProtocols) {
|
|
13
|
+
if (!isArray(protocol)) {
|
|
14
|
+
if (protocol === "*") {
|
|
15
|
+
return defaultProtocols;
|
|
16
|
+
}
|
|
17
|
+
const protocolReq = getProtocolName(req);
|
|
18
|
+
if (protocol === ":protocol") {
|
|
19
|
+
return [protocolReq].filter(Boolean);
|
|
20
|
+
}
|
|
21
|
+
if (protocolReq && protocolReq !== protocol) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
return [protocol];
|
|
25
|
+
}
|
|
26
|
+
const protocols = protocol;
|
|
27
|
+
if (protocols.includes("*")) {
|
|
28
|
+
return defaultProtocols;
|
|
29
|
+
}
|
|
30
|
+
return protocols;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=getProtocolsFromRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getProtocolsFromRequest.js","sourceRoot":"","sources":["../../../src/utils/getProtocolsFromRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AAEnC;;GAEG;AACH,SAAS,eAAe,CAAC,GAAQ;IAC/B,MAAM,EAAC,KAAK,GAAG,EAAE,EAAE,MAAM,GAAG,EAAE,EAAE,IAAI,GAAG,EAAE,EAAC,GAAG,GAAG,CAAC;IAEjD,OAAO,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC;AAC5D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAQ,EAAE,QAA2B,EAAE,gBAA0B;IACvG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QACtB,IAAI,QAAQ,KAAK,GAAG,EAAE;YACpB,OAAO,gBAAgB,CAAC;SACzB;QAED,MAAM,WAAW,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;QAEzC,IAAI,QAAQ,KAAK,WAAW,EAAE;YAC5B,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;SACtC;QAED,IAAI,WAAW,IAAI,WAAW,KAAK,QAAQ,EAAE;YAC3C,OAAO,EAAE,CAAC;SACX;QAED,OAAO,CAAC,QAAQ,CAAC,CAAC;KACnB;IAED,MAAM,SAAS,GAAa,QAAQ,CAAC;IAErC,IAAI,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAC3B,OAAO,gBAAgB,CAAC;KACzB;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import {isArray} from \"@tsed/core\";\n\n/**\n * @ignore\n */\nfunction getProtocolName(req: any) {\n const {query = {}, params = {}, body = {}} = req;\n\n return params.protocol || query.protocol || body.protocol;\n}\n\n/**\n * @ignore\n */\nexport function getProtocolsFromRequest(req: any, protocol: string | string[], defaultProtocols: string[]): string[] {\n if (!isArray(protocol)) {\n if (protocol === \"*\") {\n return defaultProtocols;\n }\n\n const protocolReq = getProtocolName(req);\n\n if (protocol === \":protocol\") {\n return [protocolReq].filter(Boolean);\n }\n\n if (protocolReq && protocolReq !== protocol) {\n return [];\n }\n\n return [protocol];\n }\n\n const protocols: string[] = protocol;\n\n if (protocols.includes(\"*\")) {\n return defaultProtocols;\n }\n\n return protocols;\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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./PassportModule";
|
|
5
|
+
export * from "./contants/constants";
|
|
6
|
+
export * from "./decorators/args";
|
|
7
|
+
export * from "./decorators/authenticate";
|
|
8
|
+
export * from "./decorators/authorize";
|
|
9
|
+
export * from "./decorators/protocol";
|
|
10
|
+
export * from "./domain/UserInfo";
|
|
11
|
+
export * from "./errors/PassportException";
|
|
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";
|
|
18
|
+
export * from "./middlewares/PassportMiddleware";
|
|
19
|
+
export * from "./services/PassportSerializerService";
|
|
20
|
+
export * from "./services/ProtocolsService";
|
|
21
|
+
export * from "./utils/getProtocolsFromRequest";
|
|
File without changes
|