nestjs-authentication 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -2
- package/README.md +108 -0
- package/SECURITY.md +15 -0
- package/dist/classes/email.password.user.d.ts +13 -0
- package/dist/classes/email.password.user.d.ts.map +1 -0
- package/dist/classes/email.password.user.js +3 -0
- package/dist/classes/email.password.user.js.map +1 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +14 -1
- package/dist/constants.js.map +1 -1
- package/dist/context/auth.context.d.ts +38 -0
- package/dist/context/auth.context.d.ts.map +1 -0
- package/dist/context/auth.context.js +39 -0
- package/dist/context/auth.context.js.map +1 -0
- package/dist/context/decorators.d.ts +25 -0
- package/dist/context/decorators.d.ts.map +1 -0
- package/dist/context/decorators.js +38 -0
- package/dist/context/decorators.js.map +1 -0
- package/dist/context/index.d.ts +5 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +21 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/interceptor.d.ts +15 -0
- package/dist/context/interceptor.d.ts.map +1 -0
- package/dist/context/interceptor.js +51 -0
- package/dist/context/interceptor.js.map +1 -0
- package/dist/context/service.d.ts +18 -0
- package/dist/context/service.d.ts.map +1 -0
- package/dist/context/service.js +45 -0
- package/dist/context/service.js.map +1 -0
- package/dist/encryptor.d.ts +20 -0
- package/dist/encryptor.d.ts.map +1 -1
- package/dist/encryptor.js +36 -6
- package/dist/encryptor.js.map +1 -1
- package/dist/encryptors/index.d.ts +3 -0
- package/dist/encryptors/index.d.ts.map +1 -0
- package/dist/encryptors/index.js +19 -0
- package/dist/encryptors/index.js.map +1 -0
- package/dist/encryptors/migrating.d.ts +28 -0
- package/dist/encryptors/migrating.d.ts.map +1 -0
- package/dist/encryptors/migrating.js +72 -0
- package/dist/encryptors/migrating.js.map +1 -0
- package/dist/encryptors/scrypt.d.ts +42 -0
- package/dist/encryptors/scrypt.d.ts.map +1 -0
- package/dist/encryptors/scrypt.js +85 -0
- package/dist/encryptors/scrypt.js.map +1 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +63 -0
- package/dist/errors.js.map +1 -0
- package/dist/guard.d.ts +115 -15
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +302 -90
- package/dist/guard.js.map +1 -1
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/dist/injection.d.ts +3 -0
- package/dist/injection.d.ts.map +1 -0
- package/dist/injection.js +9 -0
- package/dist/injection.js.map +1 -0
- package/dist/interfaces/auth.user.d.ts +16 -5
- package/dist/interfaces/auth.user.d.ts.map +1 -1
- package/dist/interfaces/auth.user.js +6 -0
- package/dist/interfaces/auth.user.js.map +1 -1
- package/dist/interfaces/encrypt.d.ts +29 -1
- package/dist/interfaces/encrypt.d.ts.map +1 -1
- package/dist/interfaces/options.d.ts +52 -5
- package/dist/interfaces/options.d.ts.map +1 -1
- package/dist/interfaces/provider.d.ts +26 -3
- package/dist/interfaces/provider.d.ts.map +1 -1
- package/dist/module.d.ts +48 -6
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +153 -50
- package/dist/module.js.map +1 -1
- package/dist/providers/auth.provider.d.ts +12 -4
- package/dist/providers/auth.provider.d.ts.map +1 -1
- package/dist/providers/auth.provider.js +7 -1
- package/dist/providers/auth.provider.js.map +1 -1
- package/dist/providers/email.password.auth.provider.d.ts +75 -0
- package/dist/providers/email.password.auth.provider.d.ts.map +1 -0
- package/dist/providers/email.password.auth.provider.js +120 -0
- package/dist/providers/email.password.auth.provider.js.map +1 -0
- package/dist/providers/memory.user.provider.d.ts +39 -6
- package/dist/providers/memory.user.provider.d.ts.map +1 -1
- package/dist/providers/memory.user.provider.js +70 -15
- package/dist/providers/memory.user.provider.js.map +1 -1
- package/dist/scopes/decorators.d.ts +41 -0
- package/dist/scopes/decorators.d.ts.map +1 -0
- package/dist/scopes/decorators.js +44 -0
- package/dist/scopes/decorators.js.map +1 -0
- package/dist/scopes/index.d.ts +4 -0
- package/dist/scopes/index.d.ts.map +1 -0
- package/dist/scopes/index.js +20 -0
- package/dist/scopes/index.js.map +1 -0
- package/dist/scopes/service.d.ts +32 -0
- package/dist/scopes/service.d.ts.map +1 -0
- package/dist/scopes/service.js +90 -0
- package/dist/scopes/service.js.map +1 -0
- package/dist/scopes/utils.d.ts +8 -0
- package/dist/scopes/utils.d.ts.map +1 -0
- package/dist/scopes/utils.js +29 -0
- package/dist/scopes/utils.js.map +1 -0
- package/dist/service.d.ts +25 -6
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +36 -5
- package/dist/service.js.map +1 -1
- package/dist/session/index.d.ts +3 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +19 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/manager.d.ts +32 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +131 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/session/request.d.ts +14 -0
- package/dist/session/request.d.ts.map +1 -0
- package/dist/session/request.js +59 -0
- package/dist/session/request.js.map +1 -0
- package/dist/strategies/emailpassword.d.ts +20 -7
- package/dist/strategies/emailpassword.d.ts.map +1 -1
- package/dist/strategies/emailpassword.js +42 -19
- package/dist/strategies/emailpassword.js.map +1 -1
- package/dist/strategies/extract.d.ts +23 -0
- package/dist/strategies/extract.d.ts.map +1 -0
- package/dist/strategies/extract.js +57 -0
- package/dist/strategies/extract.js.map +1 -0
- package/dist/strategies/index.d.ts +8 -0
- package/dist/strategies/index.d.ts.map +1 -0
- package/dist/strategies/index.js +24 -0
- package/dist/strategies/index.js.map +1 -0
- package/dist/strategies/interfaces.d.ts +65 -0
- package/dist/strategies/interfaces.d.ts.map +1 -0
- package/dist/{classes/memory.user.js → strategies/interfaces.js} +1 -1
- package/dist/strategies/interfaces.js.map +1 -0
- package/dist/strategies/jwt.d.ts +87 -15
- package/dist/strategies/jwt.d.ts.map +1 -1
- package/dist/strategies/jwt.js +140 -9
- package/dist/strategies/jwt.js.map +1 -1
- package/dist/strategies/passport.d.ts +22 -0
- package/dist/strategies/passport.d.ts.map +1 -0
- package/dist/strategies/passport.js +90 -0
- package/dist/strategies/passport.js.map +1 -0
- package/dist/strategies/registry.d.ts +33 -0
- package/dist/strategies/registry.d.ts.map +1 -0
- package/dist/strategies/registry.js +67 -0
- package/dist/strategies/registry.js.map +1 -0
- package/dist/strategies/session.d.ts +18 -0
- package/dist/strategies/session.d.ts.map +1 -0
- package/dist/strategies/session.js +79 -0
- package/dist/strategies/session.js.map +1 -0
- package/dist/transports/graphql.d.ts +28 -0
- package/dist/transports/graphql.d.ts.map +1 -0
- package/dist/transports/graphql.js +59 -0
- package/dist/transports/graphql.js.map +1 -0
- package/dist/transports/http.d.ts +13 -0
- package/dist/transports/http.d.ts.map +1 -0
- package/dist/transports/http.js +31 -0
- package/dist/transports/http.js.map +1 -0
- package/dist/transports/index.d.ts +8 -0
- package/dist/transports/index.d.ts.map +1 -0
- package/dist/transports/index.js +24 -0
- package/dist/transports/index.js.map +1 -0
- package/dist/transports/interfaces.d.ts +36 -0
- package/dist/transports/interfaces.d.ts.map +1 -0
- package/dist/transports/interfaces.js +3 -0
- package/dist/transports/interfaces.js.map +1 -0
- package/dist/transports/registry.d.ts +25 -0
- package/dist/transports/registry.d.ts.map +1 -0
- package/dist/transports/registry.js +55 -0
- package/dist/transports/registry.js.map +1 -0
- package/dist/transports/rpc.d.ts +23 -0
- package/dist/transports/rpc.d.ts.map +1 -0
- package/dist/transports/rpc.js +54 -0
- package/dist/transports/rpc.js.map +1 -0
- package/dist/transports/utils.d.ts +21 -0
- package/dist/transports/utils.d.ts.map +1 -0
- package/dist/transports/utils.js +86 -0
- package/dist/transports/utils.js.map +1 -0
- package/dist/transports/ws.d.ts +31 -0
- package/dist/transports/ws.d.ts.map +1 -0
- package/dist/transports/ws.js +52 -0
- package/dist/transports/ws.js.map +1 -0
- package/package.json +101 -58
- package/dist/classes/memory.user.d.ts +0 -7
- package/dist/classes/memory.user.d.ts.map +0 -1
- package/dist/classes/memory.user.js.map +0 -1
- package/dist/providers/auth.memory.user.provider.d.ts +0 -15
- package/dist/providers/auth.memory.user.provider.d.ts.map +0 -1
- package/dist/providers/auth.memory.user.provider.js +0 -30
- package/dist/providers/auth.memory.user.provider.js.map +0 -1
- package/dist/user.serializer.d.ts +0 -10
- package/dist/user.serializer.d.ts.map +0 -1
- package/dist/user.serializer.js +0 -53
- package/dist/user.serializer.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
export * from './classes/
|
|
1
|
+
export * from './classes/email.password.user';
|
|
2
2
|
export * from './constants';
|
|
3
|
+
export * from './context';
|
|
3
4
|
export * from './encryptor';
|
|
5
|
+
export * from './encryptors';
|
|
6
|
+
export * from './errors';
|
|
4
7
|
export * from './guard';
|
|
8
|
+
export * from './injection';
|
|
5
9
|
export * from './interfaces/auth.user';
|
|
6
10
|
export * from './interfaces/encrypt';
|
|
7
11
|
export * from './interfaces/options';
|
|
8
12
|
export * from './interfaces/provider';
|
|
9
13
|
export * from './module';
|
|
10
|
-
export * from './providers/
|
|
14
|
+
export * from './providers/email.password.auth.provider';
|
|
11
15
|
export * from './providers/auth.provider';
|
|
12
16
|
export * from './providers/memory.user.provider';
|
|
13
17
|
export * from './service';
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
18
|
+
export * from './scopes';
|
|
19
|
+
export * from './session';
|
|
20
|
+
export * from './strategies';
|
|
21
|
+
export * from './transports';
|
|
16
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,0CAA0C,CAAC;AACzD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AACjD,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,19 +14,25 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./classes/
|
|
17
|
+
__exportStar(require("./classes/email.password.user"), exports);
|
|
18
18
|
__exportStar(require("./constants"), exports);
|
|
19
|
+
__exportStar(require("./context"), exports);
|
|
19
20
|
__exportStar(require("./encryptor"), exports);
|
|
21
|
+
__exportStar(require("./encryptors"), exports);
|
|
22
|
+
__exportStar(require("./errors"), exports);
|
|
20
23
|
__exportStar(require("./guard"), exports);
|
|
24
|
+
__exportStar(require("./injection"), exports);
|
|
21
25
|
__exportStar(require("./interfaces/auth.user"), exports);
|
|
22
26
|
__exportStar(require("./interfaces/encrypt"), exports);
|
|
23
27
|
__exportStar(require("./interfaces/options"), exports);
|
|
24
28
|
__exportStar(require("./interfaces/provider"), exports);
|
|
25
29
|
__exportStar(require("./module"), exports);
|
|
26
|
-
__exportStar(require("./providers/
|
|
30
|
+
__exportStar(require("./providers/email.password.auth.provider"), exports);
|
|
27
31
|
__exportStar(require("./providers/auth.provider"), exports);
|
|
28
32
|
__exportStar(require("./providers/memory.user.provider"), exports);
|
|
29
33
|
__exportStar(require("./service"), exports);
|
|
30
|
-
__exportStar(require("./
|
|
31
|
-
__exportStar(require("./
|
|
34
|
+
__exportStar(require("./scopes"), exports);
|
|
35
|
+
__exportStar(require("./session"), exports);
|
|
36
|
+
__exportStar(require("./strategies"), exports);
|
|
37
|
+
__exportStar(require("./transports"), exports);
|
|
32
38
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA8C;AAC9C,8CAA4B;AAC5B,4CAA0B;AAC1B,8CAA4B;AAC5B,+CAA6B;AAC7B,2CAAyB;AACzB,0CAAwB;AACxB,8CAA4B;AAC5B,yDAAuC;AACvC,uDAAqC;AACrC,uDAAqC;AACrC,wDAAsC;AACtC,2CAAyB;AACzB,2EAAyD;AACzD,4DAA0C;AAC1C,mEAAiD;AACjD,4CAA0B;AAC1B,2CAAyB;AACzB,4CAA0B;AAC1B,+CAA6B;AAC7B,+CAA6B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injection.d.ts","sourceRoot":"","sources":["../src/injection.ts"],"names":[],"mappings":"AAIA,kFAAkF;AAClF,eAAO,MAAM,eAAe,QAAO,iBAAiB,GAAG,kBAAuC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectEncryptor = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
/** Injects the {@link IEncryptor} of the module (the {@link ENCRYPTOR} token). */
|
|
7
|
+
const InjectEncryptor = () => (0, common_1.Inject)(constants_1.ENCRYPTOR);
|
|
8
|
+
exports.InjectEncryptor = InjectEncryptor;
|
|
9
|
+
//# sourceMappingURL=injection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injection.js","sourceRoot":"","sources":["../src/injection.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAExC,2CAAwC;AAExC,kFAAkF;AAC3E,MAAM,eAAe,GAAG,GAA2C,EAAE,CAAC,IAAA,eAAM,EAAC,qBAAS,CAAC,CAAC;AAAlF,QAAA,eAAe,mBAAmE"}
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The payload stored in the session (and in a token) to load the user back: the id of the user (`sub`, or `_id` /
|
|
3
|
+
* `id`) and `namespace`, the name of the auth provider that loads it (`default` if not set).
|
|
4
|
+
*/
|
|
5
|
+
export type AuthUserPayload = Record<string, unknown> & {
|
|
6
|
+
sub?: unknown;
|
|
7
|
+
namespace?: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A user that builds its own payload. Optional: by default, the auth provider of the user builds it
|
|
11
|
+
* (see {@link IAuthProvider.serializeUser}).
|
|
12
|
+
*/
|
|
1
13
|
export interface IAuthUser {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} & {
|
|
5
|
-
namespace?: string;
|
|
6
|
-
};
|
|
14
|
+
/** Returns the payload stored in the session or the token to load the user back. */
|
|
15
|
+
authSerialize(): AuthUserPayload;
|
|
7
16
|
}
|
|
17
|
+
/** Returns the id of the user in a payload: `sub`, `_id` or `id`. */
|
|
18
|
+
export declare function getPayloadUserId(payload: Record<string, unknown>): unknown;
|
|
8
19
|
//# sourceMappingURL=auth.user.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.user.d.ts","sourceRoot":"","sources":["../../src/interfaces/auth.user.ts"],"names":[],"mappings":"AAAA,MAAM,
|
|
1
|
+
{"version":3,"file":"auth.user.d.ts","sourceRoot":"","sources":["../../src/interfaces/auth.user.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9F;;;GAGG;AACH,MAAM,WAAW,SAAS;IACtB,oFAAoF;IACpF,aAAa,IAAI,eAAe,CAAC;CACpC;AAED,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAE1E"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPayloadUserId = getPayloadUserId;
|
|
4
|
+
/** Returns the id of the user in a payload: `sub`, `_id` or `id`. */
|
|
5
|
+
function getPayloadUserId(payload) {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
return (_b = (_a = payload.sub) !== null && _a !== void 0 ? _a : payload._id) !== null && _b !== void 0 ? _b : payload.id;
|
|
8
|
+
}
|
|
3
9
|
//# sourceMappingURL=auth.user.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.user.js","sourceRoot":"","sources":["../../src/interfaces/auth.user.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"auth.user.js","sourceRoot":"","sources":["../../src/interfaces/auth.user.ts"],"names":[],"mappings":";;AAgBA,4CAEC;AAHD,qEAAqE;AACrE,SAAgB,gBAAgB,CAAC,OAAgC;;IAC7D,OAAO,MAAA,MAAA,OAAO,CAAC,GAAG,mCAAI,OAAO,CAAC,GAAG,mCAAI,OAAO,CAAC,EAAE,CAAC;AACpD,CAAC"}
|
|
@@ -1,8 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypts (or hashes) the passwords, and checks a password against the stored value.
|
|
3
|
+
*
|
|
4
|
+
* The default implementation is {@link Encryptor} (aes-256-ctr). Give your own with the `encryptor` option
|
|
5
|
+
* of the {@link AuthModule} (e.g. bcrypt or argon2), and inject it with {@link InjectEncryptor}.
|
|
6
|
+
*/
|
|
1
7
|
export interface IEncryptor {
|
|
2
|
-
|
|
8
|
+
/** Returns the value to store for a password. */
|
|
9
|
+
encrypt: (value: string) => string | Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Returns `true` if the password matches the stored value.
|
|
12
|
+
* Required for salted hashes (bcrypt, argon2...). If not implemented, the password is encrypted
|
|
13
|
+
* and compared with the stored value in constant time.
|
|
14
|
+
*/
|
|
15
|
+
compare?: (value: string, encrypted: string) => boolean | Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Returns `true` if this encryptor can check the stored value (e.g. it has its format).
|
|
18
|
+
* Used by {@link MigratingEncryptor} to pick the encryptor of a stored value.
|
|
19
|
+
*/
|
|
20
|
+
canVerify?: (encrypted: string) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Returns `true` if the stored value should be encrypted again (older algorithm or parameters).
|
|
23
|
+
* After a successful login, {@link EmailPasswordAuthProvider} then calls its `updatePasswordHash` option.
|
|
24
|
+
*/
|
|
25
|
+
needsRehash?: (encrypted: string) => boolean;
|
|
3
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Options of the {@link Encryptor} (aes-256-ctr).
|
|
29
|
+
*/
|
|
4
30
|
export interface IEncryptorOptions {
|
|
31
|
+
/** The initialization vector, 16 bytes as a hex string (32 characters). */
|
|
5
32
|
iv: string;
|
|
33
|
+
/** The key, 32 bytes as a hex string (64 characters). */
|
|
6
34
|
key: string;
|
|
7
35
|
}
|
|
8
36
|
//# sourceMappingURL=encrypt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../src/interfaces/encrypt.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACvB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../src/interfaces/encrypt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACvB,iDAAiD;IACjD,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACrD;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3E;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;IAC3C;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;CAChD;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,2EAA2E;IAC3E,EAAE,EAAE,MAAM,CAAC;IACX,yDAAyD;IACzD,GAAG,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -1,12 +1,59 @@
|
|
|
1
|
-
import { ModuleMetadata } from '@nestjs/common
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { InjectionToken, ModuleMetadata, OptionalFactoryDependency, Type } from '@nestjs/common';
|
|
2
|
+
import type { AuthContext } from '../context/auth.context';
|
|
3
|
+
import type { AuthGuardOptions } from '../guard';
|
|
4
|
+
import type { JwtStrategyOptions } from '../strategies/jwt';
|
|
5
|
+
import { AuthTransport } from '../transports/interfaces';
|
|
6
|
+
import { IEncryptor, IEncryptorOptions } from './encrypt';
|
|
7
|
+
/**
|
|
8
|
+
* Options of the {@link AuthModule}.
|
|
9
|
+
*/
|
|
4
10
|
export interface IAuthModuleOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Options of the default {@link Encryptor} (aes-256-ctr).
|
|
13
|
+
* Provides the `Encryptor` class, and the {@link ENCRYPTOR} token if `encryptor` is not set.
|
|
14
|
+
*/
|
|
5
15
|
encrypt?: IEncryptorOptions;
|
|
6
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Your own {@link IEncryptor}, provided with the {@link ENCRYPTOR} token: an instance, or a class
|
|
18
|
+
* instantiated by NestJS in the AuthModule. The dependencies of the class are injected: they must be
|
|
19
|
+
* provided by a global module, or by the `imports` of `forRootAsync()`.
|
|
20
|
+
*/
|
|
21
|
+
encryptor?: IEncryptor | Type<IEncryptor>;
|
|
22
|
+
/** Creates the {@link JwtStrategy} provider and registers the `jwt` strategy. */
|
|
23
|
+
jwt?: JwtStrategyOptions;
|
|
24
|
+
/**
|
|
25
|
+
* The options of the global guard (the routes with {@link Auth}, {@link Public} or {@link RequireScopes}, or all
|
|
26
|
+
* of them with `globalGuard`), overridden by the {@link Auth} metadata.
|
|
27
|
+
*/
|
|
28
|
+
defaults?: Partial<AuthGuardOptions>;
|
|
29
|
+
/** Authenticates all the routes with the global guard and the `defaults` (opt out a route with {@link Public}). Default `false`. */
|
|
30
|
+
globalGuard?: boolean;
|
|
31
|
+
/** The session property that holds the login. Default `passport` (compatible with passport sessions). */
|
|
32
|
+
sessionKey?: string;
|
|
33
|
+
/** Adds scopes to an authenticated request, e.g. from the roles of the user. */
|
|
34
|
+
scopes?: (auth: AuthContext) => string[] | Promise<string[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Your own {@link AuthTransport}s, tried before the built-in ones (http, graphql, ws, rpc) by all the guards
|
|
37
|
+
* and decorators.
|
|
38
|
+
*/
|
|
39
|
+
transports?: AuthTransport[];
|
|
40
|
+
/**
|
|
41
|
+
* Registers the global {@link AuthContextInterceptor}, so {@link AuthContextService} and {@link getAuthContext}
|
|
42
|
+
* return the auth context in everything the handlers call. Default `true`.
|
|
43
|
+
*/
|
|
44
|
+
context?: boolean;
|
|
7
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Options of `AuthModule.forRootAsync()`.
|
|
48
|
+
*/
|
|
8
49
|
export interface IAuthModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
50
|
+
/** Returns the module options. */
|
|
9
51
|
useFactory: (...args: any[]) => Promise<IAuthModuleOptions> | IAuthModuleOptions;
|
|
10
|
-
|
|
52
|
+
/** The providers injected in `useFactory`. They must be provided by a global module or one of the `imports`. */
|
|
53
|
+
inject?: (InjectionToken | OptionalFactoryDependency)[];
|
|
11
54
|
}
|
|
55
|
+
/** Alias of {@link IAuthModuleOptions}. */
|
|
56
|
+
export type AuthModuleOptions = IAuthModuleOptions;
|
|
57
|
+
/** Alias of {@link IAuthModuleAsyncOptions}. */
|
|
58
|
+
export type AuthModuleAsyncOptions = IAuthModuleAsyncOptions;
|
|
12
59
|
//# sourceMappingURL=options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/interfaces/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/interfaces/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,yBAAyB,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEjG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D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|
+
/**
|
|
3
|
+
* Finds the users with a query. Used by the {@link AuthProvider} base class, to write your own auth providers.
|
|
4
|
+
*/
|
|
1
5
|
export interface IUserProvider<User = any> {
|
|
2
|
-
|
|
6
|
+
/** Returns the user matching the query, or `undefined`. */
|
|
7
|
+
findOne: (query: Record<string, unknown>) => Promise<User | undefined>;
|
|
8
|
+
/** Stores a new password hash of a user. Optional. */
|
|
9
|
+
updatePassword?: (user: User, passwordHash: string) => Promise<void> | void;
|
|
3
10
|
}
|
|
4
|
-
|
|
5
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Loads the users of a namespace. Register it with `AuthModule.registerAuthProviders()`.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam User the user
|
|
15
|
+
* @typeParam Data the data given to `loadUser()` (credentials, session or token payload)
|
|
16
|
+
*/
|
|
17
|
+
export interface IAuthProvider<User = any, Data extends object = Record<string, any>> {
|
|
18
|
+
/**
|
|
19
|
+
* Returns the user matching the data (credentials, token payload or session payload),
|
|
20
|
+
* or `undefined` if there is none or the credentials are not valid.
|
|
21
|
+
*/
|
|
22
|
+
loadUser: (data: Data) => (User | undefined) | Promise<User | undefined>;
|
|
23
|
+
/** The namespace of the provider. The provider named `default` is used when there is no namespace. */
|
|
6
24
|
getName: () => string;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the payload stored in the session or a token to load the user back with `loadUser()`,
|
|
27
|
+
* e.g. `{ sub: user.id, namespace: 'default' }`. Used when the user does not implement {@link IAuthUser}.
|
|
28
|
+
*/
|
|
29
|
+
serializeUser?: (user: User) => AuthUserPayload;
|
|
7
30
|
}
|
|
8
31
|
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/interfaces/provider.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa,CAAC,IAAI,GAAG,GAAG;IACrC,OAAO,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/interfaces/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,IAAI,GAAG,GAAG;IACrC,2DAA2D;IAC3D,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;IACvE,sDAAsD;IACtD,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC/E;AAED;;;;;GAKG;AACH,MAAM,WAAW,aAAa,CAAC,IAAI,GAAG,GAAG,EAAE,IAAI,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAChF;;;OAGG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;IACzE,sGAAsG;IACtG,OAAO,EAAE,MAAM,MAAM,CAAC;IACtB;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,eAAe,CAAC;CACnD"}
|
package/dist/module.d.ts
CHANGED
|
@@ -1,20 +1,62 @@
|
|
|
1
|
-
import { DynamicModule,
|
|
1
|
+
import { DynamicModule, ModuleMetadata, Provider } from '@nestjs/common';
|
|
2
2
|
import { Encryptor } from './encryptor';
|
|
3
|
+
import { IEncryptor } from './interfaces/encrypt';
|
|
3
4
|
import { IAuthModuleAsyncOptions, IAuthModuleOptions } from './interfaces/options';
|
|
5
|
+
import { IAuthProvider } from './interfaces/provider';
|
|
4
6
|
import { AuthService } from './service';
|
|
5
7
|
import { EmailPasswordStrategy } from './strategies/emailpassword';
|
|
8
|
+
import { AuthStrategy } from './strategies/interfaces';
|
|
6
9
|
import { JwtStrategy } from './strategies/jwt';
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The authentication module (global).
|
|
12
|
+
*
|
|
13
|
+
* - `forRoot()` / `forRootAsync()`: configures the module once, in the root module
|
|
14
|
+
* - `registerAuthProviders()`: registers the auth providers (one per namespace)
|
|
15
|
+
*
|
|
16
|
+
* - `registerStrategies()`: registers your own strategies ({@link AuthStrategy})
|
|
17
|
+
*
|
|
18
|
+
* It provides the {@link AuthService}, the {@link AuthContextService}, the {@link AuthStrategyRegistry} with the
|
|
19
|
+
* `emailpassword`, `session` and (when configured) `jwt` strategies, the {@link ENCRYPTOR} (and the default
|
|
20
|
+
* {@link Encryptor}) and the {@link AuthScopes}, and registers the global {@link AuthGuard} and {@link AuthContextInterceptor}.
|
|
21
|
+
*/
|
|
22
|
+
export declare class AuthModule {
|
|
9
23
|
protected static createOptionsProvider(options: IAuthModuleOptions): Provider<IAuthModuleOptions>;
|
|
10
|
-
protected static createAsyncOptionsProvider(options: IAuthModuleAsyncOptions): Provider<
|
|
24
|
+
protected static createAsyncOptionsProvider(options: IAuthModuleAsyncOptions): Provider<IAuthModuleOptions>;
|
|
11
25
|
protected static createAuthServiceProvider(): Provider<AuthService>;
|
|
26
|
+
/** The default implementation, when the `encrypt` option is set. */
|
|
12
27
|
protected static createEncryptorProvider(): Provider<Encryptor | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* The {@link ENCRYPTOR}: the `encryptor` option, else the default {@link Encryptor}.
|
|
30
|
+
* With `forRoot()`, an `encryptor` class is a regular class provider.
|
|
31
|
+
*/
|
|
32
|
+
protected static createEncryptorTokenProvider(options?: IAuthModuleOptions): Provider<IEncryptor | undefined>;
|
|
13
33
|
protected static createLocalEmailPasswordStrategyProvider(): Provider<EmailPasswordStrategy>;
|
|
14
34
|
protected static createJWTStrategyProvider(): Provider<JwtStrategy | undefined>;
|
|
15
|
-
|
|
35
|
+
/** Registers the `transports` option in {@link AuthTransports}. */
|
|
36
|
+
protected static createTransportsProvider(): Provider;
|
|
37
|
+
/** Registers the built-in strategies in the registry. */
|
|
38
|
+
protected static createStrategiesProvider(): Provider;
|
|
39
|
+
static createModule(optionsProvider: Provider, imports?: IAuthModuleAsyncOptions['imports'], options?: IAuthModuleOptions): DynamicModule;
|
|
40
|
+
/** Configures the module with static options. */
|
|
16
41
|
static forRoot(options: IAuthModuleOptions): DynamicModule;
|
|
42
|
+
/** Configures the module with options returned by a factory (e.g. read from a `ConfigService`). */
|
|
17
43
|
static forRootAsync(options: IAuthModuleAsyncOptions): DynamicModule;
|
|
18
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Provides strategies ({@link AuthStrategy}) and registers them in the {@link AuthStrategyRegistry}, under their
|
|
46
|
+
* name. A strategy with the name of a built-in one (`jwt`, `emailpassword`, `session`) replaces it.
|
|
47
|
+
*
|
|
48
|
+
* @param providers class, value, factory or existing providers that resolve to an {@link AuthStrategy}
|
|
49
|
+
* @param imports the modules that provide the dependencies of the strategies (if they are not global)
|
|
50
|
+
*/
|
|
51
|
+
static registerStrategies(providers: Provider<AuthStrategy>[], imports?: ModuleMetadata['imports']): DynamicModule;
|
|
52
|
+
/**
|
|
53
|
+
* Provides auth providers ({@link IAuthProvider}) and registers them in the {@link AuthService}.
|
|
54
|
+
* Each one handles the users of its namespace (`getName()`).
|
|
55
|
+
*
|
|
56
|
+
* @param providers class, value, factory or existing providers that resolve to an {@link IAuthProvider}
|
|
57
|
+
* @param imports the modules that provide the dependencies of the providers (if they are not global),
|
|
58
|
+
* e.g. the module of a `UserRepository`
|
|
59
|
+
*/
|
|
60
|
+
static registerAuthProviders(providers: Provider<IAuthProvider<any, any>>[], imports?: ModuleMetadata['imports']): DynamicModule;
|
|
19
61
|
}
|
|
20
62
|
//# sourceMappingURL=module.d.ts.map
|
package/dist/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":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