@nest-boot/auth 6.0.0-alpha.3 → 6.0.0-beta.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 (59) hide show
  1. package/dist/auth.guard.d.ts +25 -4
  2. package/dist/auth.guard.js +65 -40
  3. package/dist/auth.guard.js.map +1 -1
  4. package/dist/auth.module.d.ts +1 -6
  5. package/dist/auth.module.js +3 -26
  6. package/dist/auth.module.js.map +1 -1
  7. package/dist/auth.service.d.ts +51 -18
  8. package/dist/auth.service.js +82 -44
  9. package/dist/auth.service.js.map +1 -1
  10. package/dist/decorators/current-personal-access-token.decorator.d.ts +1 -1
  11. package/dist/decorators/current-personal-access-token.decorator.js +4 -4
  12. package/dist/decorators/current-personal-access-token.decorator.js.map +1 -1
  13. package/dist/decorators/current-user.decorator.d.ts +1 -0
  14. package/dist/decorators/current-user.decorator.js +10 -0
  15. package/dist/decorators/current-user.decorator.js.map +1 -0
  16. package/dist/decorators/index.d.ts +1 -1
  17. package/dist/decorators/index.js +1 -1
  18. package/dist/decorators/index.js.map +1 -1
  19. package/dist/entities/index.d.ts +2 -0
  20. package/dist/{utils → entities}/index.js +2 -1
  21. package/dist/entities/index.js.map +1 -0
  22. package/dist/entities/personal-access-token.entity.d.ts +14 -0
  23. package/dist/entities/personal-access-token.entity.js +72 -0
  24. package/dist/entities/personal-access-token.entity.js.map +1 -0
  25. package/dist/entities/user.entity.d.ts +13 -0
  26. package/dist/entities/user.entity.js +68 -0
  27. package/dist/entities/user.entity.js.map +1 -0
  28. package/dist/index.d.ts +1 -3
  29. package/dist/index.js +1 -3
  30. package/dist/index.js.map +1 -1
  31. package/dist/interfaces/auth-module-options.interface.d.ts +6 -9
  32. package/dist/interfaces/index.d.ts +0 -2
  33. package/dist/interfaces/index.js +0 -2
  34. package/dist/interfaces/index.js.map +1 -1
  35. package/dist/tsconfig.build.tsbuildinfo +1 -1
  36. package/dist/utils/random-string.util.d.ts +6 -0
  37. package/dist/utils/random-string.util.js +27 -0
  38. package/dist/utils/random-string.util.js.map +1 -0
  39. package/package.json +22 -18
  40. package/dist/auth.constants.d.ts +0 -2
  41. package/dist/auth.constants.js +0 -6
  42. package/dist/auth.constants.js.map +0 -1
  43. package/dist/auth.middleware.d.ts +0 -13
  44. package/dist/auth.middleware.js +0 -67
  45. package/dist/auth.middleware.js.map +0 -1
  46. package/dist/decorators/current-entity.decorator.d.ts +0 -2
  47. package/dist/decorators/current-entity.decorator.js +0 -11
  48. package/dist/decorators/current-entity.decorator.js.map +0 -1
  49. package/dist/interfaces/access-token.interface.d.ts +0 -9
  50. package/dist/interfaces/access-token.interface.js +0 -3
  51. package/dist/interfaces/access-token.interface.js.map +0 -1
  52. package/dist/interfaces/has-permission.interface.d.ts +0 -3
  53. package/dist/interfaces/has-permission.interface.js +0 -3
  54. package/dist/interfaces/has-permission.interface.js.map +0 -1
  55. package/dist/utils/index.d.ts +0 -1
  56. package/dist/utils/index.js.map +0 -1
  57. package/dist/utils/mixin-permissions.utils.d.ts +0 -3
  58. package/dist/utils/mixin-permissions.utils.js +0 -16
  59. package/dist/utils/mixin-permissions.utils.js.map +0 -1
@@ -1,13 +1,34 @@
1
1
  import { EntityManager } from "@mikro-orm/core";
2
2
  import { type CanActivate, type ExecutionContext } from "@nestjs/common";
3
3
  import { Reflector } from "@nestjs/core";
4
+ import { AuthService } from "./auth.service";
4
5
  import { AuthModuleOptions } from "./interfaces";
6
+ /**
7
+ * Authentication guard class used to protect routes and handle requests.
8
+ */
5
9
  export declare class AuthGuard implements CanActivate {
6
- private readonly options;
7
10
  private readonly reflector;
8
- private readonly entityManager;
9
- constructor(options: AuthModuleOptions, reflector: Reflector, entityManager: EntityManager);
11
+ private readonly em;
12
+ private readonly authService;
13
+ private readonly options;
14
+ private readonly defaultRequireAuth;
15
+ constructor(reflector: Reflector, em: EntityManager, authService: AuthService, options: AuthModuleOptions);
16
+ /**
17
+ * Get internationalized text based on the specified key.
18
+ * @param key - The key of the internationalized text.
19
+ * @returns The internationalized text.
20
+ */
10
21
  private t;
22
+ /**
23
+ * Extracts the personal access token from the request.
24
+ * @param req - The request object.
25
+ * @returns The personal access token, or null if it doesn't exist.
26
+ */
27
+ private extractPersonalAccessToken;
28
+ /**
29
+ * Determines whether the request is allowed to be executed.
30
+ * @param executionContext - The execution context object.
31
+ * @returns True if the request is allowed to be executed, otherwise false.
32
+ */
11
33
  canActivate(executionContext: ExecutionContext): Promise<boolean>;
12
- getPermissions(): Promise<string[]>;
13
34
  }
@@ -22,72 +22,97 @@ const request_context_1 = require("@nest-boot/request-context");
22
22
  const common_1 = require("@nestjs/common");
23
23
  const core_2 = require("@nestjs/core");
24
24
  const lodash_1 = __importDefault(require("lodash"));
25
- const auth_constants_1 = require("./auth.constants");
26
25
  const auth_module_definition_1 = require("./auth.module-definition");
26
+ const auth_service_1 = require("./auth.service");
27
+ const entities_1 = require("./entities");
28
+ /**
29
+ * Authentication guard class used to protect routes and handle requests.
30
+ */
27
31
  let AuthGuard = class AuthGuard {
28
- constructor(options, reflector, entityManager) {
29
- this.options = options;
32
+ constructor(reflector, em, authService, options) {
30
33
  this.reflector = reflector;
31
- this.entityManager = entityManager;
34
+ this.em = em;
35
+ this.authService = authService;
36
+ this.options = options;
32
37
  this.reflector = reflector;
38
+ this.defaultRequireAuth = this.options?.defaultRequireAuth ?? true;
33
39
  }
40
+ /**
41
+ * Get internationalized text based on the specified key.
42
+ * @param key - The key of the internationalized text.
43
+ * @returns The internationalized text.
44
+ */
34
45
  t(key) {
35
46
  return request_context_1.RequestContext.get(i18n_1.I18N)?.t(key, { ns: "auth" }) ?? key;
36
47
  }
48
+ /**
49
+ * Extracts the personal access token from the request.
50
+ * @param req - The request object.
51
+ * @returns The personal access token, or null if it doesn't exist.
52
+ */
53
+ extractPersonalAccessToken(req) {
54
+ const authorizationHeader = req.get("authorization");
55
+ if (typeof authorizationHeader !== "undefined") {
56
+ const matched = authorizationHeader.match(/(\S+)\s+(\S+)/);
57
+ if (matched !== null && matched[1].toLowerCase() === "bearer") {
58
+ return matched[2];
59
+ }
60
+ }
61
+ if (typeof req.cookies?.token === "string") {
62
+ return req.cookies.token;
63
+ }
64
+ return null;
65
+ }
66
+ /**
67
+ * Determines whether the request is allowed to be executed.
68
+ * @param executionContext - The execution context object.
69
+ * @returns True if the request is allowed to be executed, otherwise false.
70
+ */
37
71
  async canActivate(executionContext) {
38
72
  if (!["http", "graphql"].includes(executionContext.getType())) {
39
73
  return true;
40
74
  }
41
- if (typeof request_context_1.RequestContext.get(request_context_1.REQUEST)
42
- ?.authMiddlewareUsed === "undefined") {
43
- return true;
44
- }
45
- // 获取方法是否需要认证
75
+ // Get whether the method requires authentication
46
76
  const requireAuth = this.reflector.get(auth_module_definition_1.REQUIRE_AUTH_METADATA_KEY, executionContext.getHandler()) ??
47
77
  this.reflector.get(auth_module_definition_1.REQUIRE_AUTH_METADATA_KEY, executionContext.getClass());
48
- // 如果默认公开或有公共访问权限直接放行
49
- if (!(requireAuth ?? this.options.defaultRequireAuth ?? false)) {
78
+ // If it's publicly accessible by default or has public access permission, allow access directly
79
+ if (!(requireAuth ?? this.defaultRequireAuth ?? false)) {
50
80
  return true;
51
81
  }
52
- const accessToken = request_context_1.RequestContext.get(auth_constants_1.AUTH_ACCESS_TOKEN);
53
- // 如果上下文中没有认证信息拒绝访问
54
- if (typeof accessToken === "undefined") {
55
- throw new common_1.UnauthorizedException(this.t("The access token is invalid."));
82
+ // Get the Request object
83
+ const req = executionContext.switchToHttp().getRequest() ??
84
+ executionContext.getArgs()[2].req;
85
+ // Extract the token
86
+ const token = this.extractPersonalAccessToken(req);
87
+ if (token === null) {
88
+ throw new common_1.UnauthorizedException(this.t("The personal access token is invalid."));
89
+ }
90
+ const personalAccessToken = await this.authService.getToken(token);
91
+ const user = await personalAccessToken?.user.load();
92
+ if (personalAccessToken === null || user == null) {
93
+ throw new common_1.UnauthorizedException(this.t("The personal access token is invalid."));
56
94
  }
57
- // 获取方法权限
95
+ request_context_1.RequestContext.set(entities_1.PersonalAccessToken, personalAccessToken);
96
+ request_context_1.RequestContext.set(entities_1.User, user);
97
+ // Get the method permissions
58
98
  const permissions = this.reflector.get(auth_module_definition_1.PERMISSIONS_METADATA_KEY, executionContext.getHandler());
59
- // 如果没有权限要求直接放行
60
- // 判断用户权限和配置权限是否有交集,如果有放行
99
+ // If there are no permission requirements, allow access directly
100
+ // Check if there is an intersection between user permissions and configured permissions, if so, allow access
61
101
  if (typeof permissions === "undefined" ||
62
- lodash_1.default.intersection(await this.getPermissions(), permissions).length > 0) {
63
- accessToken.lastUsedAt = new Date();
64
- await this.entityManager.flush();
102
+ lodash_1.default.intersection(user.permissions, permissions).length > 0) {
103
+ personalAccessToken.lastUsedAt = new Date();
104
+ await this.em.flush();
65
105
  return true;
66
106
  }
67
107
  throw new common_1.ForbiddenException(this.t("Permission denied."));
68
108
  }
69
- async getPermissions() {
70
- let permissions = [];
71
- const entity = request_context_1.RequestContext.get(auth_constants_1.AUTH_ENTITY);
72
- if (typeof entity !== "undefined") {
73
- if (typeof entity.permissions !== "undefined") {
74
- permissions = permissions.concat(entity.permissions);
75
- }
76
- else {
77
- const newPermissions = await core_1.Reference.create(entity).load("permissions");
78
- if (typeof newPermissions !== "undefined") {
79
- permissions = permissions.concat(newPermissions);
80
- }
81
- }
82
- }
83
- return permissions;
84
- }
85
109
  };
86
110
  exports.AuthGuard = AuthGuard;
87
111
  exports.AuthGuard = AuthGuard = __decorate([
88
112
  (0, common_1.Injectable)(),
89
- __param(0, (0, common_1.Inject)(auth_module_definition_1.MODULE_OPTIONS_TOKEN)),
90
- __metadata("design:paramtypes", [Object, core_2.Reflector,
91
- core_1.EntityManager])
113
+ __param(3, (0, common_1.Inject)(auth_module_definition_1.MODULE_OPTIONS_TOKEN)),
114
+ __metadata("design:paramtypes", [core_2.Reflector,
115
+ core_1.EntityManager,
116
+ auth_service_1.AuthService, Object])
92
117
  ], AuthGuard);
93
118
  //# sourceMappingURL=auth.guard.js.map
@@ -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,oBAAa;QACJ,0BAAW;GANhC,SAAS,CAuHrB"}
@@ -1,8 +1,3 @@
1
- import { type MiddlewareConsumer, type NestModule } from "@nestjs/common";
2
1
  import { ConfigurableModuleClass } from "./auth.module-definition";
3
- import { AuthModuleOptions } from "./interfaces";
4
- export declare class AuthModule extends ConfigurableModuleClass implements NestModule {
5
- private readonly options;
6
- constructor(options: AuthModuleOptions);
7
- configure(consumer: MiddlewareConsumer): void;
2
+ export declare class AuthModule extends ConfigurableModuleClass {
8
3
  }
@@ -5,42 +5,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
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
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
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
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
8
  Object.defineProperty(exports, "__esModule", { value: true });
15
9
  exports.AuthModule = void 0;
10
+ const request_context_1 = require("@nest-boot/request-context");
16
11
  const common_1 = require("@nestjs/common");
17
12
  const core_1 = require("@nestjs/core");
18
13
  const auth_guard_1 = require("./auth.guard");
19
- const auth_middleware_1 = require("./auth.middleware");
20
14
  const auth_module_definition_1 = require("./auth.module-definition");
21
15
  const auth_service_1 = require("./auth.service");
22
16
  let AuthModule = class AuthModule extends auth_module_definition_1.ConfigurableModuleClass {
23
- constructor(options) {
24
- super();
25
- this.options = options;
26
- }
27
- configure(consumer) {
28
- const middlewareConfigProxy = consumer.apply(auth_middleware_1.AuthMiddleware);
29
- if (typeof this.options.excludeRoutes !== "undefined") {
30
- middlewareConfigProxy.exclude(...this.options.excludeRoutes);
31
- }
32
- if (typeof this.options.includeRoutes !== "undefined") {
33
- middlewareConfigProxy.forRoutes(...this.options.includeRoutes);
34
- }
35
- else {
36
- middlewareConfigProxy.forRoutes("*");
37
- }
38
- }
39
17
  };
40
18
  exports.AuthModule = AuthModule;
41
19
  exports.AuthModule = AuthModule = __decorate([
42
20
  (0, common_1.Global)(),
43
21
  (0, common_1.Module)({
22
+ imports: [request_context_1.RequestContextModule],
44
23
  providers: [
45
24
  {
46
25
  provide: core_1.APP_GUARD,
@@ -50,8 +29,6 @@ exports.AuthModule = AuthModule = __decorate([
50
29
  core_1.Reflector,
51
30
  ],
52
31
  exports: [auth_service_1.AuthService],
53
- }),
54
- __param(0, (0, common_1.Inject)(auth_module_definition_1.MODULE_OPTIONS_TOKEN)),
55
- __metadata("design:paramtypes", [Object])
32
+ })
56
33
  ], AuthModule);
57
34
  //# sourceMappingURL=auth.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../src/auth.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAMwB;AACxB,uCAAoD;AAEpD,6CAAyC;AACzC,uDAAmD;AACnD,qEAGkC;AAClC,iDAA6C;AAetC,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,gDAAuB;IACrD,YAEmB,OAA0B;QAE3C,KAAK,EAAE,CAAC;QAFS,YAAO,GAAP,OAAO,CAAmB;IAG7C,CAAC;IAED,SAAS,CAAC,QAA4B;QACpC,MAAM,qBAAqB,GAAG,QAAQ,CAAC,KAAK,CAAC,gCAAc,CAAC,CAAC;QAE7D,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,KAAK,WAAW,EAAE;YACrD,qBAAqB,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;SAC9D;QAED,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,KAAK,WAAW,EAAE;YACrD,qBAAqB,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;SAChE;aAAM;YACL,qBAAqB,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;SACtC;IACH,CAAC;CACF,CAAA;AArBY,gCAAU;qBAAV,UAAU;IAZtB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,gBAAS;gBAClB,QAAQ,EAAE,sBAAS;aACpB;YACD,0BAAW;YACX,gBAAS;SACV;QACD,OAAO,EAAE,CAAC,0BAAW,CAAC;KACvB,CAAC;IAGG,WAAA,IAAA,eAAM,EAAC,6CAAoB,CAAC,CAAA;;GAFpB,UAAU,CAqBtB"}
1
+ {"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../src/auth.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,gEAAkE;AAClE,2CAAgD;AAChD,uCAAoD;AAEpD,6CAAyC;AACzC,qEAAmE;AACnE,iDAA6C;AAetC,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,gDAAuB;CAAG,CAAA;AAA7C,gCAAU;qBAAV,UAAU;IAbtB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,sCAAoB,CAAC;QAC/B,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,gBAAS;gBAClB,QAAQ,EAAE,sBAAS;aACpB;YACD,0BAAW;YACX,gBAAS;SACV;QACD,OAAO,EAAE,CAAC,0BAAW,CAAC;KACvB,CAAC;GACW,UAAU,CAAmC"}
@@ -1,29 +1,62 @@
1
- import { type AnyEntity, EntityManager, type Loaded } from "@mikro-orm/core";
2
- import { type AccessTokenInterface, AuthModuleOptions } from "./interfaces";
1
+ import { EntityManager } from "@mikro-orm/core";
2
+ import { HashService } from "@nest-boot/hash";
3
+ import { PersonalAccessToken, User } from "./entities";
4
+ import { AuthModuleOptions } from "./interfaces";
5
+ /**
6
+ * Service responsible for handling authentication-related operations.
7
+ */
3
8
  export declare class AuthService {
4
- private readonly options;
5
9
  private readonly em;
6
- constructor(options: AuthModuleOptions, em: EntityManager);
10
+ private readonly hashService;
11
+ private readonly options;
12
+ private readonly User;
13
+ private readonly PersonalAccessToken;
14
+ private readonly expiresIn?;
15
+ /**
16
+ * Constructs a new instance of the AuthService class.
17
+ * @param em The EntityManager instance.
18
+ * @param hashService The HashService instance.
19
+ * @param options The options for the Auth module.
20
+ */
21
+ constructor(em: EntityManager, hashService: HashService, options: AuthModuleOptions);
22
+ /**
23
+ * Attempts to authenticate a user with the provided email and password.
24
+ * @param email The user's email.
25
+ * @param password The user's password.
26
+ * @returns The authenticated user if successful, otherwise null.
27
+ */
28
+ attempt(email: string, password: string): Promise<import("@mikro-orm/core").Loaded<User, never, "*", never> | null>;
7
29
  /**
8
- * 生成访问令牌
9
- * @param entity
10
- * @param name
11
- * @param expiresIn
30
+ * Retrieves a personal access token by its token value.
31
+ * @param token The token value.
32
+ * @returns The personal access token if found, otherwise null.
12
33
  */
13
- createToken(entity: AnyEntity, name: string, expiresIn?: string | number): Promise<AccessTokenInterface>;
34
+ getToken(token: string): Promise<PersonalAccessToken | null>;
14
35
  /**
15
- * 获取个人访问令牌
16
- * @param token 令牌,如果不传则从上下文中获取
36
+ * Creates a new personal access token for a user.
37
+ * @param user The user for whom the token is created.
38
+ * @param name The name of the token.
39
+ * @param permissions The permissions associated with the token.
40
+ * @param expiresIn The expiration time for the token.
41
+ * @returns An object containing the token and the personal access token entity.
17
42
  */
18
- getToken(token?: string): Promise<Loaded<AccessTokenInterface> | null>;
43
+ createToken(user: User, name: string, permissions?: string[], expiresIn?: number): Promise<{
44
+ token: string;
45
+ personalAccessToken: PersonalAccessToken;
46
+ }>;
19
47
  /**
20
- * 验证访问令牌
21
- * @param token 令牌,如果不传则从上下文中获取
48
+ * Deletes a personal access token.
49
+ * @param personalAccessToken - The personal access token to be deleted.
50
+ * @returns A Promise that resolves when the token is successfully deleted.
22
51
  */
23
- verifyToken(token?: string): Promise<boolean>;
52
+ deleteToken(personalAccessToken: PersonalAccessToken): Promise<void>;
24
53
  /**
25
- * 撤销访问令牌
26
- * @param token 令牌,如果不传则从上下文中获取
54
+ * Registers a new user.
55
+ * @param name The user's name.
56
+ * @param email The user's email.
57
+ * @param password The user's password.
58
+ * @param permissions The permissions associated with the user.
59
+ * @returns The registered user.
27
60
  */
28
- revokeToken(token?: string): Promise<void>;
61
+ register(name: string, email: string, password: string, permissions?: string[]): Promise<User>;
29
62
  }
@@ -11,77 +11,115 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __importDefault = (this && this.__importDefault) || function (mod) {
15
- return (mod && mod.__esModule) ? mod : { "default": mod };
16
- };
17
14
  Object.defineProperty(exports, "__esModule", { value: true });
18
15
  exports.AuthService = void 0;
19
16
  const core_1 = require("@mikro-orm/core");
20
- const request_context_1 = require("@nest-boot/request-context");
17
+ const hash_1 = require("@nest-boot/hash");
21
18
  const common_1 = require("@nestjs/common");
22
- const crypto_1 = require("crypto");
23
- const ms_1 = __importDefault(require("ms"));
24
- const auth_constants_1 = require("./auth.constants");
25
19
  const auth_module_definition_1 = require("./auth.module-definition");
20
+ const entities_1 = require("./entities");
21
+ const random_string_util_1 = require("./utils/random-string.util");
22
+ /**
23
+ * Service responsible for handling authentication-related operations.
24
+ */
26
25
  let AuthService = class AuthService {
27
- constructor(options, em) {
28
- this.options = options;
26
+ /**
27
+ * Constructs a new instance of the AuthService class.
28
+ * @param em The EntityManager instance.
29
+ * @param hashService The HashService instance.
30
+ * @param options The options for the Auth module.
31
+ */
32
+ constructor(em, hashService, options) {
29
33
  this.em = em;
34
+ this.hashService = hashService;
35
+ this.options = options;
36
+ this.User = this.options?.entities?.User ?? entities_1.User;
37
+ this.PersonalAccessToken =
38
+ this.options?.entities?.PersonalAccessToken ?? entities_1.PersonalAccessToken;
39
+ this.expiresIn = this.options?.expiresIn;
30
40
  }
31
41
  /**
32
- * 生成访问令牌
33
- * @param entity
34
- * @param name
35
- * @param expiresIn
42
+ * Attempts to authenticate a user with the provided email and password.
43
+ * @param email The user's email.
44
+ * @param password The user's password.
45
+ * @returns The authenticated user if successful, otherwise null.
36
46
  */
37
- async createToken(entity, name, expiresIn) {
38
- const token = (0, crypto_1.randomBytes)(32).toString("hex");
39
- const _expiresIn = expiresIn ?? this.options.expiresIn;
40
- const _expiresInMs = typeof _expiresIn === "string" ? (0, ms_1.default)(_expiresIn) : _expiresIn;
41
- const accessToken = this.em.create(this.options.accessTokenEntityClass, {
42
- name,
47
+ async attempt(email, password) {
48
+ const user = await this.em.findOne(this.User, { email });
49
+ if (user === null ||
50
+ !(await this.hashService.verify(user.password, password))) {
51
+ return null;
52
+ }
53
+ return user;
54
+ }
55
+ /**
56
+ * Retrieves a personal access token by its token value.
57
+ * @param token The token value.
58
+ * @returns The personal access token if found, otherwise null.
59
+ */
60
+ async getToken(token) {
61
+ return await this.em.findOne(this.PersonalAccessToken, {
43
62
  token,
44
- entityId: entity.id,
45
- entityName: entity.constructor.name,
46
- expiresAt: _expiresInMs != null ? new Date(Date.now() + _expiresInMs) : undefined,
47
63
  });
48
- await this.em.persistAndFlush(accessToken);
49
- return accessToken;
50
64
  }
51
65
  /**
52
- * 获取个人访问令牌
53
- * @param token 令牌,如果不传则从上下文中获取
66
+ * Creates a new personal access token for a user.
67
+ * @param user The user for whom the token is created.
68
+ * @param name The name of the token.
69
+ * @param permissions The permissions associated with the token.
70
+ * @param expiresIn The expiration time for the token.
71
+ * @returns An object containing the token and the personal access token entity.
54
72
  */
55
- async getToken(token) {
56
- if (typeof token === "undefined") {
57
- return (request_context_1.RequestContext.get(auth_constants_1.AUTH_ACCESS_TOKEN) ?? null);
58
- }
59
- return await this.em.findOne(this.options.accessTokenEntityClass, {
73
+ async createToken(user, name, permissions = ["*"], expiresIn) {
74
+ const token = (0, random_string_util_1.randomString)(48);
75
+ expiresIn = expiresIn ?? this.expiresIn;
76
+ const personalAccessToken = this.em.create(this.PersonalAccessToken, {
77
+ user,
78
+ name,
60
79
  token,
80
+ permissions,
81
+ expiresAt: typeof expiresIn !== "undefined"
82
+ ? new Date(Date.now() + expiresIn)
83
+ : null,
61
84
  });
85
+ await this.em.persistAndFlush(personalAccessToken);
86
+ return { token, personalAccessToken };
62
87
  }
63
88
  /**
64
- * 验证访问令牌
65
- * @param token 令牌,如果不传则从上下文中获取
89
+ * Deletes a personal access token.
90
+ * @param personalAccessToken - The personal access token to be deleted.
91
+ * @returns A Promise that resolves when the token is successfully deleted.
66
92
  */
67
- async verifyToken(token) {
68
- return (await this.getToken(token)) !== null;
93
+ async deleteToken(personalAccessToken) {
94
+ await this.em.remove(personalAccessToken).flush();
69
95
  }
70
96
  /**
71
- * 撤销访问令牌
72
- * @param token 令牌,如果不传则从上下文中获取
97
+ * Registers a new user.
98
+ * @param name The user's name.
99
+ * @param email The user's email.
100
+ * @param password The user's password.
101
+ * @param permissions The permissions associated with the user.
102
+ * @returns The registered user.
73
103
  */
74
- async revokeToken(token) {
75
- const accessToken = await this.getToken(token);
76
- if (accessToken !== null) {
77
- await this.em.remove(accessToken).flush();
78
- }
104
+ async register(name, email, password, permissions = []) {
105
+ const hashedPassword = await this.hashService.create(password);
106
+ const user = this.em.create(this.User, {
107
+ name,
108
+ email,
109
+ password: hashedPassword,
110
+ permissions,
111
+ createdAt: new Date(),
112
+ updatedAt: new Date(),
113
+ });
114
+ await this.em.persistAndFlush(user);
115
+ return user;
79
116
  }
80
117
  };
81
118
  exports.AuthService = AuthService;
82
119
  exports.AuthService = AuthService = __decorate([
83
120
  (0, common_1.Injectable)(),
84
- __param(0, (0, common_1.Inject)(auth_module_definition_1.MODULE_OPTIONS_TOKEN)),
85
- __metadata("design:paramtypes", [Object, core_1.EntityManager])
121
+ __param(2, (0, common_1.Inject)(auth_module_definition_1.MODULE_OPTIONS_TOKEN)),
122
+ __metadata("design:paramtypes", [core_1.EntityManager,
123
+ hash_1.HashService, Object])
86
124
  ], AuthService);
87
125
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AAO,SAAS,KAAK,WAAW;gBAC9B,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;gBAClC,CAAC,CAAC,IAAI;SACX,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC;QAEnD,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW,CAAC,mBAAwC;QACxD,MAAM,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,KAAK,EAAE,CAAC;IACpD,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,QAAQ,CACZ,IAAY,EACZ,KAAa,EACb,QAAgB,EAChB,cAAwB,EAAE;QAE1B,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAE/D,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE;YACrC,IAAI;YACJ,KAAK;YACL,QAAQ,EAAE,cAAc;YACxB,WAAW;YACX,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,SAAS,EAAE,IAAI,IAAI,EAAE;SACtB,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAEpC,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA/HY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;IAgBR,WAAA,IAAA,eAAM,EAAC,6CAAoB,CAAC,CAAA;qCAFR,oBAAa;QACJ,kBAAW;GAdhC,WAAW,CA+HvB"}
@@ -1 +1 @@
1
- export declare const CurrentAccessToken: (...dataOrPipes: any[]) => ParameterDecorator;
1
+ export declare const CurrentPersonalAccessToken: (...dataOrPipes: any[]) => ParameterDecorator;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CurrentAccessToken = void 0;
3
+ exports.CurrentPersonalAccessToken = void 0;
4
4
  const request_context_1 = require("@nest-boot/request-context");
5
5
  const common_1 = require("@nestjs/common");
6
- const auth_constants_1 = require("../auth.constants");
7
- exports.CurrentAccessToken = (0, common_1.createParamDecorator)(() => {
8
- return request_context_1.RequestContext.get(auth_constants_1.AUTH_ACCESS_TOKEN);
6
+ const personal_access_token_entity_1 = require("../entities/personal-access-token.entity");
7
+ exports.CurrentPersonalAccessToken = (0, common_1.createParamDecorator)(() => {
8
+ return request_context_1.RequestContext.get(personal_access_token_entity_1.PersonalAccessToken);
9
9
  });
10
10
  //# sourceMappingURL=current-personal-access-token.decorator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"current-personal-access-token.decorator.js","sourceRoot":"","sources":["../../src/decorators/current-personal-access-token.decorator.ts"],"names":[],"mappings":";;;AAAA,gEAA4D;AAC5D,2CAAsD;AAEtD,sDAAsD;AAGzC,QAAA,kBAAkB,GAAG,IAAA,6BAAoB,EAAC,GAAG,EAAE;IAC1D,OAAO,gCAAc,CAAC,GAAG,CAAuB,kCAAiB,CAAC,CAAC;AACrE,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"current-personal-access-token.decorator.js","sourceRoot":"","sources":["../../src/decorators/current-personal-access-token.decorator.ts"],"names":[],"mappings":";;;AAAA,gEAA4D;AAC5D,2CAAsD;AAEtD,2FAA+E;AAElE,QAAA,0BAA0B,GAAG,IAAA,6BAAoB,EAAC,GAAG,EAAE;IAClE,OAAO,gCAAc,CAAC,GAAG,CAAC,kDAAmB,CAAC,CAAC;AACjD,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const CurrentUser: (...dataOrPipes: any[]) => ParameterDecorator;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CurrentUser = void 0;
4
+ const request_context_1 = require("@nest-boot/request-context");
5
+ const common_1 = require("@nestjs/common");
6
+ const user_entity_1 = require("../entities/user.entity");
7
+ exports.CurrentUser = (0, common_1.createParamDecorator)(() => {
8
+ return request_context_1.RequestContext.get(user_entity_1.User);
9
+ });
10
+ //# sourceMappingURL=current-user.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"current-user.decorator.js","sourceRoot":"","sources":["../../src/decorators/current-user.decorator.ts"],"names":[],"mappings":";;;AAAA,gEAA4D;AAC5D,2CAAsD;AAEtD,yDAA+C;AAElC,QAAA,WAAW,GAAG,IAAA,6BAAoB,EAAC,GAAG,EAAE;IACnD,OAAO,gCAAc,CAAC,GAAG,CAAC,kBAAI,CAAC,CAAC;AAClC,CAAC,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
1
  export * from "./can.decorator";
2
- export * from "./current-entity.decorator";
3
2
  export * from "./current-personal-access-token.decorator";
3
+ export * from "./current-user.decorator";
4
4
  export * from "./require-auth.decorator";
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./can.decorator"), exports);
18
- __exportStar(require("./current-entity.decorator"), exports);
19
18
  __exportStar(require("./current-personal-access-token.decorator"), exports);
19
+ __exportStar(require("./current-user.decorator"), exports);
20
20
  __exportStar(require("./require-auth.decorator"), exports);
21
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,6DAA2C;AAC3C,4EAA0D;AAC1D,2DAAyC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,4EAA0D;AAC1D,2DAAyC;AACzC,2DAAyC"}
@@ -0,0 +1,2 @@
1
+ export * from "./personal-access-token.entity";
2
+ export * from "./user.entity";
@@ -14,5 +14,6 @@ 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("./mixin-permissions.utils"), exports);
17
+ __exportStar(require("./personal-access-token.entity"), exports);
18
+ __exportStar(require("./user.entity"), exports);
18
19
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entities/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA+C;AAC/C,gDAA8B"}