@tsed/passport 7.0.0-beta.2 → 7.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jest.config.js +14 -0
- package/lib/cjs/PassportModule.js +27 -14
- package/lib/cjs/PassportModule.js.map +1 -1
- package/lib/cjs/contants/{index.js → constants.js} +1 -1
- package/lib/cjs/contants/constants.js.map +1 -0
- package/lib/cjs/decorators/authenticate.js +3 -3
- package/lib/cjs/decorators/authenticate.js.map +1 -1
- package/lib/cjs/decorators/authorize.js +3 -3
- package/lib/cjs/decorators/authorize.js.map +1 -1
- package/lib/cjs/decorators/protocol.js +2 -2
- package/lib/cjs/decorators/protocol.js.map +1 -1
- package/lib/cjs/domain/UserInfo.js +9 -6
- package/lib/cjs/domain/UserInfo.js.map +1 -1
- package/lib/cjs/index.js +21 -16
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/BeforeInstall.js +3 -0
- package/lib/cjs/interfaces/BeforeInstall.js.map +1 -0
- package/lib/cjs/interfaces/OnInstall.js.map +1 -1
- package/lib/cjs/interfaces/ProtocolMethods.js +3 -0
- package/lib/cjs/interfaces/ProtocolMethods.js.map +1 -0
- package/lib/cjs/interfaces/ProtocolOptions.js.map +1 -1
- package/lib/cjs/interfaces/{IProtocol.js → interfaces.js} +1 -1
- package/lib/cjs/interfaces/interfaces.js.map +1 -0
- package/lib/cjs/middlewares/PassportMiddleware.js +13 -10
- package/lib/cjs/middlewares/PassportMiddleware.js.map +1 -1
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/services/PassportSerializerService.js +5 -4
- package/lib/cjs/services/PassportSerializerService.js.map +1 -1
- package/lib/cjs/services/ProtocolsService.js +35 -22
- package/lib/cjs/services/ProtocolsService.js.map +1 -1
- package/lib/esm/PassportModule.js +18 -5
- package/lib/esm/PassportModule.js.map +1 -1
- package/lib/esm/contants/{index.js → constants.js} +1 -1
- package/lib/esm/contants/constants.js.map +1 -0
- package/lib/esm/decorators/authenticate.js +2 -2
- package/lib/esm/decorators/authenticate.js.map +1 -1
- package/lib/esm/decorators/authorize.js +2 -2
- package/lib/esm/decorators/authorize.js.map +1 -1
- package/lib/esm/decorators/protocol.js +1 -1
- package/lib/esm/decorators/protocol.js.map +1 -1
- package/lib/esm/domain/UserInfo.js +3 -0
- package/lib/esm/domain/UserInfo.js.map +1 -1
- package/lib/esm/index.js +21 -16
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/BeforeInstall.js +2 -0
- package/lib/esm/interfaces/BeforeInstall.js.map +1 -0
- package/lib/esm/interfaces/OnInstall.js.map +1 -1
- package/lib/esm/interfaces/ProtocolMethods.js +2 -0
- package/lib/esm/interfaces/ProtocolMethods.js.map +1 -0
- package/lib/esm/interfaces/ProtocolOptions.js.map +1 -1
- package/lib/esm/interfaces/interfaces.js +2 -0
- package/lib/esm/interfaces/interfaces.js.map +1 -0
- package/lib/esm/middlewares/PassportMiddleware.js +6 -3
- package/lib/esm/middlewares/PassportMiddleware.js.map +1 -1
- package/lib/esm/package.json +3 -0
- package/lib/esm/services/PassportSerializerService.js +3 -2
- package/lib/esm/services/PassportSerializerService.js.map +1 -1
- package/lib/esm/services/ProtocolsService.js +34 -21
- package/lib/esm/services/ProtocolsService.js.map +1 -1
- package/lib/types/PassportModule.d.ts +2 -1
- package/lib/types/contants/{index.d.ts → constants.d.ts} +0 -0
- package/lib/types/index.d.ts +15 -6
- package/lib/types/interfaces/BeforeInstall.d.ts +3 -0
- package/lib/types/interfaces/OnInstall.d.ts +1 -1
- package/lib/types/interfaces/ProtocolMethods.d.ts +5 -0
- package/lib/types/interfaces/ProtocolOptions.d.ts +2 -2
- package/lib/types/interfaces/{index.d.ts → interfaces.d.ts} +3 -4
- package/lib/types/services/ProtocolsService.d.ts +6 -5
- package/package.json +26 -22
- package/readme.md +18 -19
- package/tsconfig.compile.esm.json +1 -12
- package/lib/cjs/contants/index.js.map +0 -1
- package/lib/cjs/interfaces/IProtocol.js.map +0 -1
- package/lib/cjs/interfaces/index.js +0 -8
- package/lib/cjs/interfaces/index.js.map +0 -1
- package/lib/esm/contants/index.js.map +0 -1
- package/lib/esm/interfaces/IProtocol.js +0 -2
- package/lib/esm/interfaces/IProtocol.js.map +0 -1
- package/lib/esm/interfaces/index.js +0 -5
- package/lib/esm/interfaces/index.js.map +0 -1
- package/lib/types/interfaces/IProtocol.d.ts +0 -4
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/passport",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.20",
|
|
4
4
|
"description": "Passport package for Ts.ED framework",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
7
|
+
"module": "./lib/esm/index.js",
|
|
7
8
|
"typings": "./lib/types/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
"types": "./lib/types/index.d.ts",
|
|
@@ -12,45 +13,48 @@
|
|
|
12
13
|
"default": "./lib/esm/index.js"
|
|
13
14
|
},
|
|
14
15
|
"scripts": {
|
|
15
|
-
"
|
|
16
|
+
"clean": "rm -rf lib",
|
|
17
|
+
"build": "yarn clean && yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
16
18
|
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
17
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",
|
|
18
22
|
"start": "ts-node src/index.ts"
|
|
19
23
|
},
|
|
20
24
|
"dependencies": {
|
|
21
|
-
"tslib": "2.
|
|
25
|
+
"tslib": "2.4.0"
|
|
22
26
|
},
|
|
23
27
|
"devDependencies": {
|
|
24
|
-
"@tsed/common": "7.0.0-beta.
|
|
25
|
-
"@tsed/core": "7.0.0-beta.
|
|
26
|
-
"@tsed/di": "7.0.0-beta.
|
|
27
|
-
"@
|
|
28
|
-
"@types/passport
|
|
28
|
+
"@tsed/common": "7.0.0-beta.20",
|
|
29
|
+
"@tsed/core": "7.0.0-beta.20",
|
|
30
|
+
"@tsed/di": "7.0.0-beta.20",
|
|
31
|
+
"@tsed/platform-router": "7.0.0-beta.20",
|
|
32
|
+
"@types/passport": "1.0.7",
|
|
33
|
+
"@types/passport-http": "0.3.9",
|
|
29
34
|
"@types/passport-local": "1.0.34",
|
|
30
35
|
"@types/passport-strategy": "0.2.35",
|
|
31
|
-
"passport": "0.
|
|
36
|
+
"passport": "0.5.2",
|
|
32
37
|
"passport-http": "0.3.0",
|
|
33
38
|
"passport-local": "1.0.0",
|
|
34
39
|
"passport-strategy": "1.0.0"
|
|
35
40
|
},
|
|
36
41
|
"peerDependencies": {
|
|
37
|
-
"@tsed/common": "^7.0.0-beta.
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"@tsed/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"passport": ">=0.4.1",
|
|
45
|
-
"passport-http": ">=0.3.0",
|
|
46
|
-
"passport-local": ">=1.0.0",
|
|
47
|
-
"passport-strategy": ">=1.0.0"
|
|
42
|
+
"@tsed/common": "^7.0.0-beta.20",
|
|
43
|
+
"passport": ">=0.4.1"
|
|
44
|
+
},
|
|
45
|
+
"peerDependenciesMeta": {
|
|
46
|
+
"@tsed/common": {
|
|
47
|
+
"optional": false
|
|
48
|
+
}
|
|
48
49
|
},
|
|
49
50
|
"repository": "https://github.com/tsedio/tsed",
|
|
50
51
|
"bugs": {
|
|
51
52
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
52
53
|
},
|
|
53
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
54
|
+
"homepage": "https://github.com/tsedio/tsed/tree/beta/packages/security/passport",
|
|
54
55
|
"author": "Romain Lenzotti",
|
|
55
|
-
"license": "MIT"
|
|
56
|
+
"license": "MIT",
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"tag": "beta"
|
|
59
|
+
}
|
|
56
60
|
}
|
package/readme.md
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
[](https://badge.fury.io/js/%40tsed%2Fcommon)
|
|
12
12
|
[](https://github.com/semantic-release/semantic-release)
|
|
13
13
|
[](https://github.com/prettier/prettier)
|
|
14
|
-
[](https://github.com/sponsors/romakita)
|
|
15
|
+
[](https://opencollective.com/tsed)
|
|
15
16
|
|
|
16
17
|
</div>
|
|
17
18
|
|
|
@@ -32,6 +33,7 @@ A package of Ts.ED framework. See website: https://tsed.io/#/tutorials/passport
|
|
|
32
33
|
## Installation
|
|
33
34
|
|
|
34
35
|
Run npm command (or yarn):
|
|
36
|
+
|
|
35
37
|
```bash
|
|
36
38
|
npm install --save @tsed/passport passport
|
|
37
39
|
npm install --save-dev @types/passport
|
|
@@ -40,18 +42,15 @@ npm install --save-dev @types/passport
|
|
|
40
42
|
## Configure your server
|
|
41
43
|
|
|
42
44
|
Add this configuration to your server:
|
|
43
|
-
```typescript
|
|
44
|
-
import {Configuration} from "@tsed/common"
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
```typescript
|
|
47
|
+
import {Configuration} from "@tsed/common";
|
|
47
48
|
|
|
48
49
|
@Configuration({
|
|
49
50
|
componentsScan: [
|
|
50
|
-
|
|
51
|
+
`./protocols/*.ts` // scan protocols directory
|
|
51
52
|
],
|
|
52
|
-
passport: {
|
|
53
|
-
|
|
54
|
-
}
|
|
53
|
+
passport: {}
|
|
55
54
|
})
|
|
56
55
|
export class Server {}
|
|
57
56
|
```
|
|
@@ -61,19 +60,20 @@ export class Server {}
|
|
|
61
60
|
A Protocol is a special Ts.ED service which is used to declare a Passport Strategy and handle Passport lifecycle.
|
|
62
61
|
|
|
63
62
|
Here an example with the PassportLocal:
|
|
63
|
+
|
|
64
64
|
```typescript
|
|
65
65
|
import {BodyParams, Req, Format, Required} from "@tsed/common";
|
|
66
66
|
import {Strategy} from "passport-local";
|
|
67
67
|
import {Unauthorized} from "@tsed/exceptions";
|
|
68
|
-
import {Protocol, OnInstall, OnVerify} from "@tsed/passport";
|
|
68
|
+
import {Protocol, OnInstall, OnVerify} from "@tsed/passport";
|
|
69
69
|
import {Inject} from "@tsed/di";
|
|
70
|
-
import {UserService} from "../services/UserService"
|
|
70
|
+
import {UserService} from "../services/UserService";
|
|
71
71
|
|
|
72
72
|
export class Credentials {
|
|
73
73
|
@Required()
|
|
74
|
-
@Format(
|
|
74
|
+
@Format("email")
|
|
75
75
|
email: string;
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
@Required()
|
|
78
78
|
password: string;
|
|
79
79
|
}
|
|
@@ -94,11 +94,11 @@ export class LocalProtocol implements OnVerify, OnInstall {
|
|
|
94
94
|
const user = await this.userService.find(credentials);
|
|
95
95
|
|
|
96
96
|
if (!user) {
|
|
97
|
-
|
|
97
|
+
throw new Unauthorized("Unauthorized user");
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
if(!user.verifyPassword()) {
|
|
101
|
-
|
|
99
|
+
|
|
100
|
+
if (!user.verifyPassword()) {
|
|
101
|
+
throw new Unauthorized("Unauthorized user");
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
return user;
|
|
@@ -135,18 +135,17 @@ This controller will provide required all endpoints which will be used by the di
|
|
|
135
135
|
See our complete example on [Ts.ED passport repository](https://github.com/tsedio/tsed-example-passportjs).
|
|
136
136
|
|
|
137
137
|
## Contributors
|
|
138
|
+
|
|
138
139
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
|
|
139
140
|
|
|
140
141
|
<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
141
142
|
|
|
142
|
-
|
|
143
143
|
## Backers
|
|
144
144
|
|
|
145
145
|
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
146
146
|
|
|
147
147
|
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>
|
|
148
148
|
|
|
149
|
-
|
|
150
149
|
## Sponsors
|
|
151
150
|
|
|
152
151
|
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)]
|
|
@@ -155,7 +154,7 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
|
|
|
155
154
|
|
|
156
155
|
The MIT License (MIT)
|
|
157
156
|
|
|
158
|
-
Copyright (c) 2016 -
|
|
157
|
+
Copyright (c) 2016 - 2022 Romain Lenzotti
|
|
159
158
|
|
|
160
159
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
161
160
|
|
|
@@ -8,16 +8,5 @@
|
|
|
8
8
|
"declaration": true,
|
|
9
9
|
"declarationDir": "./lib/types"
|
|
10
10
|
},
|
|
11
|
-
"exclude": [
|
|
12
|
-
"node_modules",
|
|
13
|
-
"test",
|
|
14
|
-
"lib",
|
|
15
|
-
"benchmark",
|
|
16
|
-
"coverage",
|
|
17
|
-
"spec",
|
|
18
|
-
"**/*.benchmark.ts",
|
|
19
|
-
"**/*.spec.ts",
|
|
20
|
-
"keys",
|
|
21
|
-
"jest.config.js"
|
|
22
|
-
]
|
|
11
|
+
"exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
|
|
23
12
|
}
|
|
@@ -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":"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,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
(0, tslib_1.__exportStar)(require("./ProtocolOptions"), exports);
|
|
5
|
-
(0, tslib_1.__exportStar)(require("./IProtocol"), exports);
|
|
6
|
-
(0, tslib_1.__exportStar)(require("./OnInstall"), exports);
|
|
7
|
-
(0, 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,iEAAkC;AAClC,2DAA4B;AAC5B,2DAA4B;AAC5B,0DAA2B","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":"index.js","sourceRoot":"","sources":["../../../src/contants/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG,UAAU,CAAC","sourcesContent":["export const PROVIDER_TYPE_PROTOCOL = \"protocol\";\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":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":"AAkBA,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC","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"]}
|