nestjs-authentication 0.2.1 → 0.4.2

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.
Files changed (87) hide show
  1. package/dist/classes/memory.user.d.ts +4 -5
  2. package/dist/classes/memory.user.d.ts.map +1 -1
  3. package/dist/classes/memory.user.js +0 -5
  4. package/dist/classes/memory.user.js.map +1 -1
  5. package/dist/constants.d.ts +3 -0
  6. package/dist/constants.d.ts.map +1 -0
  7. package/dist/constants.js +6 -0
  8. package/dist/constants.js.map +1 -0
  9. package/dist/encryptor.d.ts +7 -0
  10. package/dist/encryptor.d.ts.map +1 -0
  11. package/dist/encryptor.js +31 -0
  12. package/dist/encryptor.js.map +1 -0
  13. package/dist/guard.d.ts +20 -12
  14. package/dist/guard.d.ts.map +1 -1
  15. package/dist/guard.js +87 -48
  16. package/dist/guard.js.map +1 -1
  17. package/dist/index.d.ts +13 -13
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +13 -13
  20. package/dist/index.js.map +1 -1
  21. package/dist/interfaces/auth.user.d.ts +8 -0
  22. package/dist/interfaces/auth.user.d.ts.map +1 -0
  23. package/dist/interfaces/{jwt.payload.js → auth.user.js} +1 -1
  24. package/dist/interfaces/auth.user.js.map +1 -0
  25. package/dist/interfaces/encrypt.d.ts +2 -2
  26. package/dist/interfaces/encrypt.d.ts.map +1 -1
  27. package/dist/interfaces/options.d.ts +4 -2
  28. package/dist/interfaces/options.d.ts.map +1 -1
  29. package/dist/interfaces/provider.d.ts +4 -4
  30. package/dist/interfaces/provider.d.ts.map +1 -1
  31. package/dist/module.d.ts +14 -4
  32. package/dist/module.d.ts.map +1 -1
  33. package/dist/module.js +89 -29
  34. package/dist/module.js.map +1 -1
  35. package/dist/providers/auth.memory.user.provider.d.ts +15 -0
  36. package/dist/providers/auth.memory.user.provider.d.ts.map +1 -0
  37. package/dist/providers/auth.memory.user.provider.js +30 -0
  38. package/dist/providers/auth.memory.user.provider.js.map +1 -0
  39. package/dist/providers/auth.provider.d.ts +8 -11
  40. package/dist/providers/auth.provider.d.ts.map +1 -1
  41. package/dist/providers/auth.provider.js +10 -33
  42. package/dist/providers/auth.provider.js.map +1 -1
  43. package/dist/providers/{memory.provider.d.ts → memory.user.provider.d.ts} +1 -1
  44. package/dist/providers/memory.user.provider.d.ts.map +1 -0
  45. package/dist/providers/{memory.provider.js → memory.user.provider.js} +5 -5
  46. package/dist/providers/memory.user.provider.js.map +1 -0
  47. package/dist/service.d.ts +2 -10
  48. package/dist/service.d.ts.map +1 -1
  49. package/dist/service.js +2 -35
  50. package/dist/service.js.map +1 -1
  51. package/dist/strategies/emailpassword.d.ts +14 -0
  52. package/dist/strategies/emailpassword.d.ts.map +1 -0
  53. package/dist/strategies/{local.js → emailpassword.js} +18 -17
  54. package/dist/strategies/emailpassword.js.map +1 -0
  55. package/dist/strategies/jwt.d.ts +22 -0
  56. package/dist/strategies/jwt.d.ts.map +1 -0
  57. package/dist/strategies/jwt.js +40 -0
  58. package/dist/strategies/jwt.js.map +1 -0
  59. package/dist/user.serializer.d.ts +4 -8
  60. package/dist/user.serializer.d.ts.map +1 -1
  61. package/dist/user.serializer.js +4 -13
  62. package/dist/user.serializer.js.map +1 -1
  63. package/package.json +43 -40
  64. package/dist/classes/user.d.ts +0 -8
  65. package/dist/classes/user.d.ts.map +0 -1
  66. package/dist/classes/user.js +0 -7
  67. package/dist/classes/user.js.map +0 -1
  68. package/dist/controller.d.ts +0 -8
  69. package/dist/controller.d.ts.map +0 -1
  70. package/dist/controller.js +0 -39
  71. package/dist/controller.js.map +0 -1
  72. package/dist/interfaces/emailpassword.d.ts +0 -5
  73. package/dist/interfaces/emailpassword.d.ts.map +0 -1
  74. package/dist/interfaces/emailpassword.js +0 -3
  75. package/dist/interfaces/emailpassword.js.map +0 -1
  76. package/dist/interfaces/jwt.payload.d.ts +0 -6
  77. package/dist/interfaces/jwt.payload.d.ts.map +0 -1
  78. package/dist/interfaces/jwt.payload.js.map +0 -1
  79. package/dist/interfaces/login.request.d.ts +0 -6
  80. package/dist/interfaces/login.request.d.ts.map +0 -1
  81. package/dist/interfaces/login.request.js +0 -3
  82. package/dist/interfaces/login.request.js.map +0 -1
  83. package/dist/providers/memory.provider.d.ts.map +0 -1
  84. package/dist/providers/memory.provider.js.map +0 -1
  85. package/dist/strategies/local.d.ts +0 -16
  86. package/dist/strategies/local.d.ts.map +0 -1
  87. package/dist/strategies/local.js.map +0 -1
@@ -1,8 +1,7 @@
1
- import { User } from './user';
2
- export declare class MemoryUser extends User {
1
+ import { IAuthUser } from '../interfaces/auth.user';
2
+ export interface MemoryUser extends IAuthUser {
3
3
  _id: any;
4
- firstName: string;
5
- lastName: string;
6
- roles: string[];
4
+ email: string;
5
+ passwordEncrypted: string;
7
6
  }
8
7
  //# sourceMappingURL=memory.user.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"memory.user.d.ts","sourceRoot":"","sources":["../../src/classes/memory.user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,qBAAa,UAAW,SAAQ,IAAI;IAChC,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;CACnB"}
1
+ {"version":3,"file":"memory.user.d.ts","sourceRoot":"","sources":["../../src/classes/memory.user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,MAAM,WAAW,UAAW,SAAQ,SAAS;IACzC,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;CAC7B"}
@@ -1,8 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemoryUser = void 0;
4
- const user_1 = require("./user");
5
- class MemoryUser extends user_1.User {
6
- }
7
- exports.MemoryUser = MemoryUser;
8
3
  //# sourceMappingURL=memory.user.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"memory.user.js","sourceRoot":"","sources":["../../src/classes/memory.user.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAE9B,MAAa,UAAW,SAAQ,WAAI;CAKnC;AALD,gCAKC"}
1
+ {"version":3,"file":"memory.user.js","sourceRoot":"","sources":["../../src/classes/memory.user.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export declare const MODULE_OPTIONS_TOKEN = "nestjs-authentication:options";
2
+ export declare const MODULE_PROVIDER_REGISTER = "nestjs-authentication:provider.register";
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,kCAAkC,CAAC;AACpE,eAAO,MAAM,wBAAwB,4CAA4C,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MODULE_PROVIDER_REGISTER = exports.MODULE_OPTIONS_TOKEN = void 0;
4
+ exports.MODULE_OPTIONS_TOKEN = 'nestjs-authentication:options';
5
+ exports.MODULE_PROVIDER_REGISTER = 'nestjs-authentication:provider.register';
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,+BAA+B,CAAC;AACvD,QAAA,wBAAwB,GAAG,yCAAyC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { IEncryptor, IEncryptorOptions } from './interfaces/encrypt';
2
+ export declare class Encryptor implements IEncryptor {
3
+ protected options: IEncryptorOptions;
4
+ constructor(options: IEncryptorOptions);
5
+ encrypt(value: string): string;
6
+ }
7
+ //# sourceMappingURL=encryptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryptor.d.ts","sourceRoot":"","sources":["../src/encryptor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAErE,qBACa,SAAU,YAAW,UAAU;IAC5B,SAAS,CAAC,OAAO,EAAE,iBAAiB;gBAA1B,OAAO,EAAE,iBAAiB;IAEhD,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAUjC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Encryptor = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const crypto_1 = require("crypto");
15
+ let Encryptor = class Encryptor {
16
+ constructor(options) {
17
+ this.options = options;
18
+ }
19
+ encrypt(value) {
20
+ const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', Buffer.from(this.options.key, 'hex'), Buffer.from(this.options.iv, 'hex'));
21
+ let crypted = cipher.update(value, 'utf8', 'hex');
22
+ crypted += cipher.final('hex');
23
+ return crypted;
24
+ }
25
+ };
26
+ Encryptor = __decorate([
27
+ (0, common_1.Injectable)(),
28
+ __metadata("design:paramtypes", [Object])
29
+ ], Encryptor);
30
+ exports.Encryptor = Encryptor;
31
+ //# sourceMappingURL=encryptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryptor.js","sourceRoot":"","sources":["../src/encryptor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,mCAAwC;AAKxC,IAAa,SAAS,GAAtB,MAAa,SAAS;IAClB,YAAsB,OAA0B;QAA1B,YAAO,GAAP,OAAO,CAAmB;IAAG,CAAC;IAEpD,OAAO,CAAC,KAAa;QACjB,MAAM,MAAM,GAAG,IAAA,uBAAc,EACzB,aAAa,EACb,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,EACpC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,CACtC,CAAC;QACF,IAAI,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAClD,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC/B,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ,CAAA;AAbY,SAAS;IADrB,IAAA,mBAAU,GAAE;;GACA,SAAS,CAarB;AAbY,8BAAS"}
package/dist/guard.d.ts CHANGED
@@ -1,18 +1,26 @@
1
+ /// <reference types="qs" />
1
2
  import { CanActivate, ExecutionContext } from '@nestjs/common';
2
- import { Request } from 'express';
3
- import * as passport from 'passport';
4
- import { User } from './classes/user';
5
- export declare const scopes: Map<any, any>;
6
- export interface IAuthGuardOptions extends passport.AuthenticateOptions {
7
- isAuth?: boolean;
8
- strategy: string | string[];
3
+ import { Request, Response } from 'express';
4
+ import { AuthenticateOptions } from 'passport';
5
+ export interface AuthGuardOptions {
6
+ fromSession?: boolean;
7
+ required?: boolean;
8
+ strategies: {
9
+ [strategyName: string]: AuthenticateOptions;
10
+ };
9
11
  }
10
12
  export declare class AuthGuard implements CanActivate {
11
- protected readonly options: IAuthGuardOptions;
12
- constructor(options: IAuthGuardOptions & {
13
- [key: string]: any;
14
- });
13
+ protected readonly options: AuthGuardOptions;
14
+ static scopes: Map<any, any>;
15
+ static registerScopes(_scopes: AuthenticateOptions['scope']): void;
16
+ constructor(options: AuthGuardOptions);
17
+ getRequestReponse(context: ExecutionContext): {
18
+ request: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
19
+ response: Response<any, Record<string, any>>;
20
+ next: any;
21
+ };
22
+ authenticateFromSession(request: Request, response: Response): Promise<boolean>;
15
23
  canActivate(context: ExecutionContext): Promise<boolean>;
16
- login(user: User, request: Request): Promise<User>;
24
+ login(user: Record<string, unknown>, options: AuthenticateOptions, request: Request): Promise<Record<string, unknown>>;
17
25
  }
18
26
  //# sourceMappingURL=guard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAyB,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,eAAO,MAAM,MAAM,eAAY,CAAC;AAEhC,MAAM,WAAW,iBAAkB,SAAQ,QAAQ,CAAC,mBAAmB;IACnE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC/B;AAED,qBAAa,SAAU,YAAW,WAAW;IACzC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;gBAElC,OAAO,EAAE,iBAAiB,GAAG;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE;IAezD,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAgDxD,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAY3D"}
1
+ {"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAA2B,MAAM,gBAAgB,CAAC;AACxF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAiB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEzD,MAAM,WAAW,gBAAgB;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE;QAAE,CAAC,YAAY,EAAE,MAAM,GAAG,mBAAmB,CAAA;KAAE,CAAC;CAC/D;AAED,qBAAa,SAAU,YAAW,WAAW;IAkB7B,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,gBAAgB;IAdxD,MAAM,CAAC,MAAM,gBAAa;IAC1B,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC;gBAa5B,OAAO,EAAE,gBAAgB;IAaxD,iBAAiB,CAAC,OAAO,EAAE,gBAAgB;;;;;IAqBrC,uBAAuB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAW/E,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IA4CxD,KAAK,CACP,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,mBAAmB,EAC5B,OAAO,EAAE,OAAO,GACjB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAUtC"}
package/dist/guard.js CHANGED
@@ -8,79 +8,118 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.AuthGuard = exports.scopes = void 0;
15
+ exports.AuthGuard = void 0;
13
16
  const common_1 = require("@nestjs/common");
14
- const passport = require("passport");
15
- exports.scopes = new Map();
17
+ const passport_1 = __importDefault(require("passport"));
16
18
  class AuthGuard {
17
19
  constructor(options) {
18
- this.options = Object.assign(Object.assign({}, options), { authInfo: true });
19
- if (typeof this.options.scope === 'string') {
20
- this.options.scope = [this.options.scope];
20
+ var _a, _b;
21
+ this.options = options;
22
+ for (const strategy in this.options.strategies) {
23
+ const options = this.options.strategies[strategy];
24
+ options.authInfo = (_a = options === null || options === void 0 ? void 0 : options.authInfo) !== null && _a !== void 0 ? _a : true;
25
+ options.session = (_b = options === null || options === void 0 ? void 0 : options.session) !== null && _b !== void 0 ? _b : false;
26
+ AuthGuard.registerScopes(options === null || options === void 0 ? void 0 : options.scope);
21
27
  }
22
- if (Array.isArray(this.options.scope)) {
23
- for (const scope of this.options.scope) {
24
- exports.scopes.set(scope, scope);
25
- }
28
+ }
29
+ static registerScopes(_scopes) {
30
+ if (_scopes === undefined) {
31
+ return;
26
32
  }
27
- if (typeof this.options.strategy === 'string') {
28
- this.options.strategy = [this.options.strategy];
33
+ let arrayScopes;
34
+ if (!Array.isArray(_scopes)) {
35
+ arrayScopes = _scopes.split(' ');
29
36
  }
37
+ else {
38
+ arrayScopes = _scopes;
39
+ }
40
+ arrayScopes.forEach((s) => AuthGuard.scopes.set(s, s));
41
+ }
42
+ getRequestReponse(context) {
43
+ let request;
44
+ let response;
45
+ let next;
46
+ if (context.getType() === 'http') {
47
+ const ctx = context.switchToHttp();
48
+ [request, response, next] = [ctx.getRequest(), ctx.getResponse(), ctx.getNext()];
49
+ }
50
+ else if (context.getType() === 'graphql') {
51
+ const ctx = context.getArgByIndex(2);
52
+ request = ctx.req;
53
+ response = ctx.res;
54
+ next = (err) => {
55
+ throw err;
56
+ };
57
+ }
58
+ else {
59
+ throw new common_1.NotImplementedException(`Auth Context ${context.getType()} not implemented`);
60
+ }
61
+ return { request, response, next };
62
+ }
63
+ authenticateFromSession(request, response) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ return yield new Promise((resolve, reject) => passport_1.default.session()(request, response, () => {
66
+ if (request.isAuthenticated()) {
67
+ return resolve(true);
68
+ }
69
+ resolve(false);
70
+ }));
71
+ });
30
72
  }
31
73
  canActivate(context) {
32
74
  return __awaiter(this, void 0, void 0, function* () {
33
- const httpCtx = context.switchToHttp();
34
- let [request, response, next] = [httpCtx.getRequest(), httpCtx.getResponse(), httpCtx.getNext()];
35
- if (typeof request !== 'object') {
36
- request = context.getArgByIndex(2).request;
37
- response = request.res;
38
- next = (err) => {
39
- throw err;
40
- };
41
- }
42
- for (const strategy of this.options.strategy) {
43
- if (strategy === 'local' && request.isAuthenticated() === true) {
75
+ const { request, response, next } = this.getRequestReponse(context);
76
+ if (this.options.fromSession) {
77
+ const isAuthenticatedFromSession = yield this.authenticateFromSession(request, response);
78
+ if (isAuthenticatedFromSession) {
44
79
  return true;
45
80
  }
46
- else {
47
- yield new Promise((resolve, reject) => passport.authenticate(strategy, this.options, (err, user, info) => __awaiter(this, void 0, void 0, function* () {
48
- request.authInfo = info;
49
- try {
50
- if (err !== undefined && err !== null) {
51
- throw err;
52
- }
53
- if (typeof user !== 'object' && this.options.isAuth) {
54
- throw new Error('User not found');
55
- }
56
- if (typeof user === 'object') {
57
- yield this.login(user, request);
58
- }
59
- resolve(true);
81
+ }
82
+ for (const strategy in this.options.strategies) {
83
+ const options = this.options.strategies[strategy];
84
+ const success = yield new Promise((resolve, reject) => passport_1.default.authenticate(strategy, options !== null && options !== void 0 ? options : {}, (err, user, authInfo) => __awaiter(this, void 0, void 0, function* () {
85
+ if (request.authInfo === undefined) {
86
+ request.authInfo = [];
87
+ }
88
+ request.authInfo[strategy] = authInfo;
89
+ try {
90
+ if (err !== undefined && err !== null) {
91
+ return reject(err);
60
92
  }
61
- catch (e) {
62
- reject(new common_1.UnauthorizedException(typeof (e === null || e === void 0 ? void 0 : e.message) === 'string' ? e.message : 'Uncaught error'));
93
+ if (typeof user === 'object' && typeof user !== null) {
94
+ yield this.login(user, options, request);
95
+ return resolve(true);
63
96
  }
64
- }))(request, response, next));
97
+ return resolve(false);
98
+ }
99
+ catch (e) {
100
+ return reject(e);
101
+ }
102
+ }))(request, response, next));
103
+ if (success === true) {
104
+ return success;
65
105
  }
66
106
  }
67
- return true;
107
+ return this.options.required ? request.isAuthenticated() : true;
68
108
  });
69
109
  }
70
- login(user, request) {
110
+ login(user, options, request) {
71
111
  return __awaiter(this, void 0, void 0, function* () {
72
- request.oauth2Scope = this.options.scope;
73
- yield new Promise((resolve, reject) => {
74
- request.logIn(user, (loginErr) => {
75
- if (loginErr instanceof Error) {
76
- return reject(loginErr);
112
+ return yield new Promise((resolve, reject) => {
113
+ request.logIn(user, options, (e) => {
114
+ if (e !== undefined && e !== null) {
115
+ return reject(e);
77
116
  }
78
117
  resolve(user);
79
118
  });
80
119
  });
81
- return user;
82
120
  });
83
121
  }
84
122
  }
85
123
  exports.AuthGuard = AuthGuard;
124
+ AuthGuard.scopes = new Map();
86
125
  //# sourceMappingURL=guard.js.map
package/dist/guard.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"guard.js","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAsF;AAEtF,qCAAqC;AAIxB,QAAA,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;AAOhC,MAAa,SAAS;IAGlB,YAAY,OAAmD;QAC3D,IAAI,CAAC,OAAO,mCAAQ,OAAO,KAAE,QAAQ,EAAE,IAAI,GAAE,CAAC;QAC9C,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE;YACxC,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AK,CAAC,CAAC;qBACzB;oBAAC,OAAO,CAAC,EAAE;wBACR,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;qBACpB;gBACL,CAAC,CAAA,CACJ,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,CAC7B,CAAC;gBACF,IAAI,OAAO,KAAK,IAAI,EAAE;oBAClB,OAAO,OAAO,CAAC;iBAClB;aACJ;YAED,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACpE,CAAC;KAAA;IAEK,KAAK,CACP,IAA6B,EAC7B,OAA4B,EAC5B,OAAgB;;YAEhB,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACzC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAQ,EAAE,EAAE;oBACtC,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,EAAE;wBAC/B,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;qBACpB;oBACD,OAAO,CAAC,IAAI,CAAC,CAAC;gBAClB,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;QACP,CAAC;KAAA;;AAxHL,8BAyHC;AArHU,gBAAM,GAAG,IAAI,GAAG,EAAE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,16 +1,16 @@
1
- export * from './module';
2
- export * from './service';
3
- export * from './controller';
4
- export * from './providers/auth.provider';
5
- export * from './providers/memory.provider';
6
- export * from './interfaces/emailpassword';
7
- export * from './interfaces/encrypt';
8
- export * from './interfaces/jwt.payload';
9
- export * from './interfaces/provider';
10
- export * from './interfaces/options';
11
- export * from './interfaces/login.request';
12
- export * from './strategies/local';
13
1
  export * from './classes/memory.user';
14
- export * from './classes/user';
2
+ export * from './constants';
3
+ export * from './encryptor';
15
4
  export * from './guard';
5
+ export * from './interfaces/auth.user';
6
+ export * from './interfaces/encrypt';
7
+ export * from './interfaces/options';
8
+ export * from './interfaces/provider';
9
+ export * from './module';
10
+ export * from './providers/auth.memory.user.provider';
11
+ export * from './providers/auth.provider';
12
+ export * from './providers/memory.user.provider';
13
+ export * from './service';
14
+ export * from './strategies/emailpassword';
15
+ export * from './strategies/jwt';
16
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,uCAAuC,CAAC;AACtD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AACjD,cAAc,WAAW,CAAC;AAC1B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -10,19 +10,19 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./module"), exports);
14
- __exportStar(require("./service"), exports);
15
- __exportStar(require("./controller"), exports);
16
- __exportStar(require("./providers/auth.provider"), exports);
17
- __exportStar(require("./providers/memory.provider"), exports);
18
- __exportStar(require("./interfaces/emailpassword"), exports);
19
- __exportStar(require("./interfaces/encrypt"), exports);
20
- __exportStar(require("./interfaces/jwt.payload"), exports);
21
- __exportStar(require("./interfaces/provider"), exports);
22
- __exportStar(require("./interfaces/options"), exports);
23
- __exportStar(require("./interfaces/login.request"), exports);
24
- __exportStar(require("./strategies/local"), exports);
25
13
  __exportStar(require("./classes/memory.user"), exports);
26
- __exportStar(require("./classes/user"), exports);
14
+ __exportStar(require("./constants"), exports);
15
+ __exportStar(require("./encryptor"), exports);
27
16
  __exportStar(require("./guard"), exports);
17
+ __exportStar(require("./interfaces/auth.user"), exports);
18
+ __exportStar(require("./interfaces/encrypt"), exports);
19
+ __exportStar(require("./interfaces/options"), exports);
20
+ __exportStar(require("./interfaces/provider"), exports);
21
+ __exportStar(require("./module"), exports);
22
+ __exportStar(require("./providers/auth.memory.user.provider"), exports);
23
+ __exportStar(require("./providers/auth.provider"), exports);
24
+ __exportStar(require("./providers/memory.user.provider"), exports);
25
+ __exportStar(require("./service"), exports);
26
+ __exportStar(require("./strategies/emailpassword"), exports);
27
+ __exportStar(require("./strategies/jwt"), exports);
28
28
  //# 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,2CAAyB;AACzB,4CAA0B;AAC1B,+CAA6B;AAC7B,4DAA0C;AAC1C,8DAA4C;AAC5C,6DAA2C;AAC3C,uDAAqC;AACrC,2DAAyC;AACzC,wDAAsC;AACtC,uDAAqC;AACrC,6DAA2C;AAC3C,qDAAmC;AACnC,wDAAsC;AACtC,iDAA+B;AAC/B,0CAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wDAAsC;AACtC,8CAA4B;AAC5B,8CAA4B;AAC5B,0CAAwB;AACxB,yDAAuC;AACvC,uDAAqC;AACrC,uDAAqC;AACrC,wDAAsC;AACtC,2CAAyB;AACzB,wEAAsD;AACtD,4DAA0C;AAC1C,mEAAiD;AACjD,4CAA0B;AAC1B,6DAA2C;AAC3C,mDAAiC"}
@@ -0,0 +1,8 @@
1
+ export interface IAuthUser {
2
+ authSerialize(): {
3
+ [key: string]: any;
4
+ } & {
5
+ namespace?: string;
6
+ };
7
+ }
8
+ //# sourceMappingURL=auth.user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.user.d.ts","sourceRoot":"","sources":["../../src/interfaces/auth.user.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACtB,aAAa,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,GAAG;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACpE"}
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=jwt.payload.js.map
3
+ //# sourceMappingURL=auth.user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.user.js","sourceRoot":"","sources":["../../src/interfaces/auth.user.ts"],"names":[],"mappings":""}
@@ -1,7 +1,7 @@
1
- export interface IEncrypt {
1
+ export interface IEncryptor {
2
2
  encrypt: (value: string) => string;
3
3
  }
4
- export interface IEncryptOptions {
4
+ export interface IEncryptorOptions {
5
5
  iv: string;
6
6
  key: string;
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../src/interfaces/encrypt.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACrB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CACtC;AACD,MAAM,WAAW,eAAe;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACf"}
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;CACtC;AACD,MAAM,WAAW,iBAAiB;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACf"}
@@ -1,7 +1,9 @@
1
1
  import { ModuleMetadata } from '@nestjs/common/interfaces';
2
- import { IEncryptOptions } from './encrypt';
2
+ import { StrategyOptions as JWTOptions } from 'passport-jwt';
3
+ import { IEncryptorOptions } from './encrypt';
3
4
  export interface IAuthModuleOptions {
4
- encrypt: IEncryptOptions;
5
+ encrypt?: IEncryptorOptions;
6
+ jwt?: JWTOptions;
5
7
  }
6
8
  export interface IAuthModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
7
9
  useFactory: (...args: any[]) => Promise<IAuthModuleOptions> | IAuthModuleOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/interfaces/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,WAAW,kBAAkB;IAC/B,OAAO,EAAE,eAAe,CAAC;CAC5B;AAED,MAAM,WAAW,uBAAwB,SAAQ,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC;IAC5E,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,CAAC;IACjF,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;CAClB"}
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/interfaces/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,eAAe,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,WAAW,kBAAkB;IAC/B,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,GAAG,CAAC,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,uBAAwB,SAAQ,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC;IAC5E,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,CAAC;IACjF,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;CAClB"}
@@ -1,8 +1,8 @@
1
- export interface IUserProvider<U = any> {
2
- findOne: (data: any) => Promise<U | undefined>;
1
+ export interface IUserProvider<User = any> {
2
+ findOne: (data: Record<string, unknown>) => Promise<User | undefined>;
3
3
  }
4
- export interface IAuthProvider<U = any> {
5
- loadUser: (data: any) => (U | undefined) | Promise<U | undefined>;
4
+ export interface IAuthProvider<User = any> {
5
+ loadUser: (data: Record<string, unknown>) => (User | undefined) | Promise<User | undefined>;
6
6
  getName: () => string;
7
7
  }
8
8
  //# 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,CAAC,GAAG,GAAG;IAClC,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;CAClD;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,GAAG;IAClC,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IAClE,OAAO,EAAE,MAAM,MAAM,CAAC;CACzB"}
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,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;CACzE;AAED,MAAM,WAAW,aAAa,CAAC,IAAI,GAAG,GAAG;IACrC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;IAC5F,OAAO,EAAE,MAAM,MAAM,CAAC;CACzB"}
package/dist/module.d.ts CHANGED
@@ -1,10 +1,20 @@
1
- import { DynamicModule, MiddlewareConsumer, NestModule } from '@nestjs/common';
1
+ import { DynamicModule, MiddlewareConsumer, NestModule, Provider } from '@nestjs/common';
2
+ import { Encryptor } from './encryptor';
2
3
  import { IAuthModuleAsyncOptions, IAuthModuleOptions } from './interfaces/options';
3
4
  import { AuthService } from './service';
5
+ import { EmailPasswordStrategy } from './strategies/emailpassword';
6
+ import { JwtStrategy } from './strategies/jwt';
4
7
  export declare class AuthModule implements NestModule {
5
8
  configure(consumer: MiddlewareConsumer): any;
6
- protected static createAuthService(opts: IAuthModuleOptions): AuthService;
7
- static register(options: IAuthModuleOptions): DynamicModule;
8
- static registerAsync(options: IAuthModuleAsyncOptions): DynamicModule;
9
+ protected static createOptionsProvider(options: IAuthModuleOptions): Provider<IAuthModuleOptions>;
10
+ protected static createAsyncOptionsProvider(options: IAuthModuleAsyncOptions): Provider<Promise<IAuthModuleOptions> | IAuthModuleOptions>;
11
+ protected static createAuthServiceProvider(): Provider<AuthService>;
12
+ protected static createEncryptorProvider(): Provider<Encryptor | undefined>;
13
+ protected static createLocalEmailPasswordStrategyProvider(): Provider<EmailPasswordStrategy>;
14
+ protected static createJWTStrategyProvider(): Provider<JwtStrategy | undefined>;
15
+ static createModule(optionsProvider: Provider): DynamicModule;
16
+ static forRoot(options: IAuthModuleOptions): DynamicModule;
17
+ static forRootAsync(options: IAuthModuleAsyncOptions): DynamicModule;
18
+ static registerAuthProviders(providers: Provider[]): DynamicModule;
9
19
  }
10
20
  //# sourceMappingURL=module.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,kBAAkB,EAAU,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI/F,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAIxC,qBAEa,UAAW,YAAW,UAAU;IACzC,SAAS,CAAC,QAAQ,EAAE,kBAAkB,GAAG,GAAG;IAM5C,SAAS,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,GAAG,WAAW;IAIzE,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,GAAG,aAAa;IAkB3D,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,uBAAuB,GAAG,aAAa;CAkBxE"}
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,kBAAkB,EAAU,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAIzG,OAAO,EAAE,SAAS,EAAE,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