@tsed/passport 7.0.0-alpha.2 → 7.0.0-beta.11
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 +33 -32
- 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
|
@@ -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";
|
|
File without changes
|
|
File without changes
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PlatformContext } from "@tsed/common";
|
|
2
2
|
import { InjectorService, Provider } from "@tsed/di";
|
|
3
3
|
import { Strategy } from "passport";
|
|
4
|
+
import type { ProtocolMethods } from "../interfaces/ProtocolMethods";
|
|
4
5
|
/**
|
|
5
6
|
* @ignore
|
|
6
7
|
*/
|
|
@@ -14,7 +15,7 @@ export declare class ProtocolsService {
|
|
|
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
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,55 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/passport",
|
|
3
|
-
"version": "7.0.0-
|
|
3
|
+
"version": "7.0.0-beta.11",
|
|
4
4
|
"description": "Passport package for Ts.ED framework",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
"
|
|
5
|
+
"source": "./src/index.ts",
|
|
6
|
+
"main": "./lib/cjs/index.js",
|
|
7
|
+
"module": "./lib/esm/index.js",
|
|
8
|
+
"typings": "./lib/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
"types": "./lib/types/index.d.ts",
|
|
11
|
+
"import": "./lib/esm/index.js",
|
|
12
|
+
"require": "./lib/cjs/index.js",
|
|
13
|
+
"default": "./lib/esm/index.js"
|
|
11
14
|
},
|
|
12
15
|
"scripts": {
|
|
13
|
-
"
|
|
16
|
+
"clean": "rm -rf lib",
|
|
17
|
+
"build": "yarn clean && yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
18
|
+
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
19
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
20
|
+
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
|
|
21
|
+
"test": "cross-env NODE_ENV=test yarn jest --max-workers=2",
|
|
14
22
|
"start": "ts-node src/index.ts"
|
|
15
23
|
},
|
|
16
24
|
"dependencies": {
|
|
17
|
-
"tslib": "2.
|
|
25
|
+
"tslib": "2.3.1"
|
|
18
26
|
},
|
|
19
27
|
"devDependencies": {
|
|
20
|
-
"@tsed/common": "7.0.0-
|
|
21
|
-
"@tsed/core": "7.0.0-
|
|
22
|
-
"@tsed/di": "7.0.0-
|
|
23
|
-
"@types/passport": "1.0.
|
|
24
|
-
"@types/passport-http": "0.3.
|
|
25
|
-
"@types/passport-local": "1.0.
|
|
28
|
+
"@tsed/common": "7.0.0-beta.11",
|
|
29
|
+
"@tsed/core": "7.0.0-beta.11",
|
|
30
|
+
"@tsed/di": "7.0.0-beta.11",
|
|
31
|
+
"@types/passport": "1.0.7",
|
|
32
|
+
"@types/passport-http": "0.3.9",
|
|
33
|
+
"@types/passport-local": "1.0.34",
|
|
26
34
|
"@types/passport-strategy": "0.2.35",
|
|
27
|
-
"passport": "0.
|
|
35
|
+
"passport": "0.5.2",
|
|
28
36
|
"passport-http": "0.3.0",
|
|
29
37
|
"passport-local": "1.0.0",
|
|
30
38
|
"passport-strategy": "1.0.0"
|
|
31
39
|
},
|
|
32
40
|
"peerDependencies": {
|
|
33
|
-
"@tsed/common": "^7.0.0-
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"@tsed/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"passport": "^0.4.1",
|
|
41
|
-
"passport-http": "^0.3.0",
|
|
42
|
-
"passport-local": "^1.0.0",
|
|
43
|
-
"passport-strategy": "^1.0.0"
|
|
41
|
+
"@tsed/common": "^7.0.0-beta.11",
|
|
42
|
+
"passport": ">=0.4.1"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"@tsed/common": {
|
|
46
|
+
"optional": false
|
|
47
|
+
}
|
|
44
48
|
},
|
|
45
49
|
"repository": "https://github.com/tsedio/tsed",
|
|
46
50
|
"bugs": {
|
|
47
51
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
48
52
|
},
|
|
49
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
53
|
+
"homepage": "https://github.com/tsedio/tsed/tree/beta/packages/security/passport",
|
|
50
54
|
"author": "Romain Lenzotti",
|
|
51
|
-
"license": "MIT"
|
|
52
|
-
"publishConfig": {
|
|
53
|
-
"tag": "alpha"
|
|
54
|
-
}
|
|
55
|
+
"license": "MIT"
|
|
55
56
|
}
|
package/readme.md
CHANGED
|
@@ -32,6 +32,7 @@ A package of Ts.ED framework. See website: https://tsed.io/#/tutorials/passport
|
|
|
32
32
|
## Installation
|
|
33
33
|
|
|
34
34
|
Run npm command (or yarn):
|
|
35
|
+
|
|
35
36
|
```bash
|
|
36
37
|
npm install --save @tsed/passport passport
|
|
37
38
|
npm install --save-dev @types/passport
|
|
@@ -40,18 +41,15 @@ npm install --save-dev @types/passport
|
|
|
40
41
|
## Configure your server
|
|
41
42
|
|
|
42
43
|
Add this configuration to your server:
|
|
43
|
-
```typescript
|
|
44
|
-
import {Configuration} from "@tsed/common"
|
|
45
44
|
|
|
46
|
-
|
|
45
|
+
```typescript
|
|
46
|
+
import {Configuration} from "@tsed/common";
|
|
47
47
|
|
|
48
48
|
@Configuration({
|
|
49
49
|
componentsScan: [
|
|
50
|
-
|
|
50
|
+
`./protocols/*.ts` // scan protocols directory
|
|
51
51
|
],
|
|
52
|
-
passport: {
|
|
53
|
-
|
|
54
|
-
}
|
|
52
|
+
passport: {}
|
|
55
53
|
})
|
|
56
54
|
export class Server {}
|
|
57
55
|
```
|
|
@@ -61,19 +59,20 @@ export class Server {}
|
|
|
61
59
|
A Protocol is a special Ts.ED service which is used to declare a Passport Strategy and handle Passport lifecycle.
|
|
62
60
|
|
|
63
61
|
Here an example with the PassportLocal:
|
|
62
|
+
|
|
64
63
|
```typescript
|
|
65
64
|
import {BodyParams, Req, Format, Required} from "@tsed/common";
|
|
66
65
|
import {Strategy} from "passport-local";
|
|
67
66
|
import {Unauthorized} from "@tsed/exceptions";
|
|
68
|
-
import {Protocol, OnInstall, OnVerify} from "@tsed/passport";
|
|
67
|
+
import {Protocol, OnInstall, OnVerify} from "@tsed/passport";
|
|
69
68
|
import {Inject} from "@tsed/di";
|
|
70
|
-
import {UserService} from "../services/UserService"
|
|
69
|
+
import {UserService} from "../services/UserService";
|
|
71
70
|
|
|
72
71
|
export class Credentials {
|
|
73
72
|
@Required()
|
|
74
|
-
@Format(
|
|
73
|
+
@Format("email")
|
|
75
74
|
email: string;
|
|
76
|
-
|
|
75
|
+
|
|
77
76
|
@Required()
|
|
78
77
|
password: string;
|
|
79
78
|
}
|
|
@@ -94,11 +93,11 @@ export class LocalProtocol implements OnVerify, OnInstall {
|
|
|
94
93
|
const user = await this.userService.find(credentials);
|
|
95
94
|
|
|
96
95
|
if (!user) {
|
|
97
|
-
|
|
96
|
+
throw new Unauthorized("Unauthorized user");
|
|
98
97
|
}
|
|
99
|
-
|
|
100
|
-
if(!user.verifyPassword()) {
|
|
101
|
-
|
|
98
|
+
|
|
99
|
+
if (!user.verifyPassword()) {
|
|
100
|
+
throw new Unauthorized("Unauthorized user");
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
return user;
|
|
@@ -135,18 +134,17 @@ This controller will provide required all endpoints which will be used by the di
|
|
|
135
134
|
See our complete example on [Ts.ED passport repository](https://github.com/tsedio/tsed-example-passportjs).
|
|
136
135
|
|
|
137
136
|
## Contributors
|
|
137
|
+
|
|
138
138
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
|
|
139
139
|
|
|
140
140
|
<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
141
141
|
|
|
142
|
-
|
|
143
142
|
## Backers
|
|
144
143
|
|
|
145
144
|
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
146
145
|
|
|
147
146
|
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>
|
|
148
147
|
|
|
149
|
-
|
|
150
148
|
## Sponsors
|
|
151
149
|
|
|
152
150
|
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.compile.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"module": "ES2020",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"outDir": "./lib/esm",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationDir": "./lib/types"
|
|
10
|
+
},
|
|
11
|
+
"exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
|
|
12
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
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;IAazB,YACU,GAAwB,EACxB,gBAAkC,EAClC,kBAA6C;QAF7C,QAAG,GAAH,GAAG,CAAqB;QACxB,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,uBAAkB,GAAlB,kBAAkB,CAA2B;IACpD,CAAC;IAEJ,OAAO;QACL,kBAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC;QACxF,kBAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC;QAE5F,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,CAAC,OAAO,CAAC,CAAC,QAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAElH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,iBAAiB;QACf,MAAM,EAAC,YAAY,EAAE,WAAW,EAAC,GAAG,IAAI,CAAC;QACzC,QAAQ,IAAI,CAAC,YAAY,EAAE;YACzB,KAAK,SAAS;gBACZ,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,kBAAQ,CAAC,UAAU,CAAC,EAAC,YAAY,EAAC,CAAC,CAAC,CAAC;gBAClD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,kBAAQ,CAAC,OAAO,CAAC,EAAC,WAAW,EAAC,CAAC,CAAC,CAAC;gBAE9C,OAAO;YAET;gBACE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,YAAY,mCAAmC,CAAC,CAAC;SACvF;IACH,CAAC;CACF,CAAA;AAvCC;IADC,iBAAQ,CAAC,uBAAuB,CAAC;;oDACb;AAGrB;IADC,iBAAQ,CAAC,sBAAsB,CAAC;;mDACZ;AAGrB;IADC,iBAAQ,CAAC,eAAe,CAAC;;oDACL;AAGrB;IADC,eAAM,EAAE;sCACD,eAAM;8CAAC;AAXJ,cAAc;IAH1B,eAAM,CAAC;QACN,KAAK,EAAE,sBAAa,CAAC,SAAS;KAC/B,CAAC;6CAee,4BAAmB;QACN,mCAAgB;QACd,qDAAyB;GAhB5C,cAAc,CAyC1B;AAzCY,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(\"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 $onInit(): Promise<any> | void {\n Passport.serializeUser(this.passportSerializer.serialize.bind(this.passportSerializer));\n Passport.deserializeUser(this.passportSerializer.deserialize.bind(this.passportSerializer));\n\n this.protocolsService.getProtocols().forEach((provider: Provider<any>) => this.protocolsService.invoke(provider));\n\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.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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contants/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG,UAAU,CAAC","sourcesContent":["export const PROVIDER_TYPE_PROTOCOL = \"protocol\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"args.js","sourceRoot":"","sources":["../../src/decorators/args.ts"],"names":[],"mappings":";;;AAAA,yCAAqC;AACrC,qCAAyC;AAEzC;;;GAGG;AACH,SAAgB,IAAI;IAClB,OAAO,oBAAa,CAAC,gBAAO,CAAC,eAAe,CAAC,CAAC,CAAC;AACjD,CAAC;AAFD,oBAEC;AAED,SAAgB,GAAG,CAAC,KAAa;IAC/B,OAAO,oBAAa,CAAC,gBAAO,CAAC,iBAAiB,KAAK,EAAE,CAAC,CAAC,CAAC;AAC1D,CAAC;AAFD,kBAEC","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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../../src/decorators/authenticate.ts"],"names":[],"mappings":";;;AAAA,yCAAqC;AAErC,0EAAqE;AACrE,qCAAyC;AACzC,yCAAsC;AAOtC,SAAgB,YAAY,CAAC,WAA8B,GAAG,EAAE,UAA+B,EAAE;IAC/F,OAAO,oBAAa,CAClB,gBAAO,CAAC,uCAAkB,EAAE;QAC1B,QAAQ;QACR,MAAM,EAAE,cAAc;QACtB,WAAW,EAAE,OAAO,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW;QAC3E,OAAO;KACR,CAAC,EACF,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC7D,OAAO,iBAAQ,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAZD,oCAYC","sourcesContent":["import {UseAuth} from \"@tsed/common\";\nimport {AuthenticateOptions as PassportAuthenticateOptions} from \"passport\";\nimport {PassportMiddleware} from \"../middlewares/PassportMiddleware\";\nimport {useDecorators} from \"@tsed/core\";\nimport {Security} from \"@tsed/schema\";\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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../src/decorators/authorize.ts"],"names":[],"mappings":";;;AAAA,yCAAqC;AAErC,0EAAqE;AACrE,qCAAyC;AACzC,yCAAsC;AAOtC,SAAgB,SAAS,CAAC,WAA8B,GAAG,EAAE,UAA4B,EAAE;IACzF,OAAO,oBAAa,CAClB,gBAAO,CAAC,uCAAkB,EAAE;QAC1B,QAAQ;QACR,MAAM,EAAE,WAAW;QACnB,WAAW,EAAE,OAAO,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW;QAC3E,OAAO;KACR,CAAC,EACF,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC7D,OAAO,iBAAQ,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAZD,8BAYC","sourcesContent":["import {UseAuth} from \"@tsed/common\";\nimport {AuthenticateOptions} from \"passport\";\nimport {PassportMiddleware} from \"../middlewares/PassportMiddleware\";\nimport {useDecorators} from \"@tsed/core\";\nimport {Security} from \"@tsed/schema\";\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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/decorators/protocol.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AACnD,iCAAmD;AAEnD,0CAAmD;AAEnD;;;;;GAKG;AACH,SAAgB,QAAQ,CAAU,OAAoC;IACpE,OAAO,oBAAa,CAClB,eAAU,CAAC;QACT,IAAI,EAAE,iCAAsB;KAC7B,CAAC,EACF,eAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,EAC7B,kBAAa,CAAC;QACZ,QAAQ,EAAE;YACR,SAAS,EAAE;gBACT,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO;aACxB;SACF;KACF,CAAC,CACH,CAAC;AACJ,CAAC;AAdD,4BAcC","sourcesContent":["import {StoreSet, useDecorators} from \"@tsed/core\";\nimport {Configuration, Injectable} from \"@tsed/di\";\nimport {ProtocolOptions} from \"../interfaces/ProtocolOptions\";\nimport {PROVIDER_TYPE_PROTOCOL} from \"../contants\";\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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UserInfo.js","sourceRoot":"","sources":["../../src/domain/UserInfo.ts"],"names":[],"mappings":";;;;AAAA,yCAA8C;AAE9C,MAAa,QAAQ;CAUpB;AARC;IADC,iBAAQ,EAAE;;oCACA;AAIX;IAFC,iBAAQ,EAAE;IACV,eAAM,CAAC,OAAO,CAAC;;uCACF;AAGd;IADC,iBAAQ,EAAE;;0CACM;AATnB,4BAUC","sourcesContent":["import {Format, Property} from \"@tsed/schema\";\n\nexport class UserInfo {\n @Property()\n id: string;\n\n @Property()\n @Format(\"email\")\n email: string;\n\n @Property()\n password: string;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PassportException.js","sourceRoot":"","sources":["../../src/errors/PassportException.ts"],"names":[],"mappings":";;;AAAA,iDAA2C;AAE3C,MAAa,iBAAkB,SAAQ,sBAAS;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;AALD,8CAKC","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/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import "./PassportModule";
|
|
2
|
-
export * from "./decorators/authenticate";
|
|
3
|
-
export * from "./decorators/authorize";
|
|
4
|
-
export * from "./decorators/protocol";
|
|
5
|
-
export * from "./decorators/args";
|
|
6
|
-
export * from "./interfaces";
|
|
7
|
-
export * from "./domain/UserInfo";
|
|
8
|
-
export * from "./errors/PassportException";
|
|
9
|
-
export * from "./contants";
|
|
10
|
-
export * from "./services/ProtocolsService";
|
|
11
|
-
export * from "./services/PassportSerializerService";
|
|
12
|
-
export * from "./middlewares/PassportMiddleware";
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAE1B,YAAY;AACZ,oEAA0C;AAC1C,iEAAuC;AACvC,gEAAsC;AACtC,4DAAkC;AAElC,aAAa;AACb,uDAA6B;AAC7B,4DAAkC;AAClC,qEAA2C;AAE3C,0BAA0B;AAC1B,qDAA2B;AAC3B,sEAA4C;AAC5C,+EAAqD;AAErD,cAAc;AACd,2EAAiD","sourcesContent":["import \"./PassportModule\";\n\n// Decorator\nexport * from \"./decorators/authenticate\";\nexport * from \"./decorators/authorize\";\nexport * from \"./decorators/protocol\";\nexport * from \"./decorators/args\";\n\n// Interfaces\nexport * from \"./interfaces\";\nexport * from \"./domain/UserInfo\";\nexport * from \"./errors/PassportException\";\n\n// Registries and Services\nexport * from \"./contants\";\nexport * from \"./services/ProtocolsService\";\nexport * from \"./services/PassportSerializerService\";\n\n// Middlewares\nexport * from \"./middlewares/PassportMiddleware\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IProtocol.js","sourceRoot":"","sources":["../../src/interfaces/IProtocol.ts"],"names":[],"mappings":"","sourcesContent":["import {OnInstall} from \"./OnInstall\";\nimport {OnVerify} from \"./OnVerify\";\n\nexport interface IProtocol extends OnVerify, OnInstall {}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
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;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
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"]}
|
|
@@ -1 +0,0 @@
|
|
|
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<T = any> {\n name: string;\n useStrategy: Type<Strategy>;\n settings: T;\n}\n"]}
|
package/lib/interfaces/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./ProtocolOptions"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./IProtocol"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./OnInstall"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./OnVerify"), exports);
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAkBA,4DAAkC;AAClC,sDAA4B;AAC5B,sDAA4B;AAC5B,qDAA2B","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {ProtocolOptions} from \"./ProtocolOptions\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n passport: {\n userProperty?: string;\n pauseStream?: string;\n userInfoModel?: Type<any> | false;\n protocols?: {\n [protocolName: string]: Partial<ProtocolOptions>;\n };\n };\n }\n }\n}\n\nexport * from \"./ProtocolOptions\";\nexport * from \"./IProtocol\";\nexport * from \"./OnInstall\";\nexport * from \"./OnVerify\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PassportMiddleware.js","sourceRoot":"","sources":["../../src/middlewares/PassportMiddleware.ts"],"names":[],"mappings":";;;;;AAAA,yCAAyD;AACzD,mEAA8D;AAC9D,8EAAyE;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,iDAAuB,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,eAAM,CAAC,mCAAgB,CAAC;sCACP,mCAAgB;4DAAC;AAOnC;IAAW,mBAAA,gBAAO,EAAE,CAAA;;;;6CAiBnB;AA1BU,kBAAkB;IAD9B,mBAAU,EAAE;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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PassportSerializerService.js","sourceRoot":"","sources":["../../src/services/PassportSerializerService.ts"],"names":[],"mappings":";;;;AACA,iCAA2C;AAC3C,mDAAyD;AACzD,iDAA4C;AAE5C;;GAEG;AAEH,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IAIpC,SAAS,CAAC,IAAc,EAAE,IAAS;QACjC,IAAI;YACF,MAAM,GAAG,GAAG,uBAAS,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,yBAAW,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,aAAQ,CAAC,wBAAwB,EAAE,mBAAQ,CAAC;;wDACL;AAF7B,yBAAyB;IADrC,YAAO,EAAE;GACG,yBAAyB,CA2BrC;AA3BY,8DAAyB","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {Constant, Service} from \"@tsed/di\";\nimport {deserialize, serialize} from \"@tsed/json-mapper\";\nimport {UserInfo} from \"../domain/UserInfo\";\n\n/**\n * @ignore\n */\n@Service()\nexport class PassportSerializerService {\n @Constant(\"passport.userInfoModel\", UserInfo)\n private model: Type<UserInfo> | boolean;\n\n serialize(user: UserInfo, done: any) {\n try {\n const obj = serialize(user, {type: this.model});\n\n // remove password from serialized object\n 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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProtocolsService.js","sourceRoot":"","sources":["../../src/services/ProtocolsService.ts"],"names":[],"mappings":"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","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 {IProtocol, ProtocolOptions} from \"../interfaces\";\nimport {PROVIDER_TYPE_PROTOCOL} from \"../contants\";\nimport {promisify} from \"util\";\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 Array.from(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 public invoke(provider: Provider): any {\n const {name, useStrategy: strategy, settings} = this.getOptions(provider);\n const protocol = this.injector.get<IProtocol & any>(provider.provide)!;\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 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 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 };\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getProtocolsFromRequest.js","sourceRoot":"","sources":["../../src/utils/getProtocolsFromRequest.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;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,SAAgB,uBAAuB,CAAC,GAAQ,EAAE,QAA2B,EAAE,gBAA0B;IACvG,IAAI,CAAC,cAAO,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;AA1BD,0DA0BC","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"]}
|