@tc-libs/authentication 1.30.0 → 3.0.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/package.json CHANGED
@@ -1,9 +1,19 @@
1
1
  {
2
2
  "name": "@tc-libs/authentication",
3
- "version": "1.30.0",
3
+ "version": "3.0.0",
4
4
  "dependencies": {
5
- "@tc-libs/errors": "1.30.0",
6
- "@tc-libs/helper": "1.30.0"
5
+ "@tc-libs/errors": "3.0.0",
6
+ "@tc-libs/helper": "3.0.0",
7
+ "@nestjs/common": "^11.0.12",
8
+ "@nestjs/passport": "^11.0.5",
9
+ "@nestjs/jwt": "^11.0.0",
10
+ "passport-apple": "^2.0.2",
11
+ "rxjs": "^7.8.2",
12
+ "passport-google-oauth20": "^2.0.0",
13
+ "passport-jwt": "^4.0.1",
14
+ "@nestjs/core": "^11.0.12",
15
+ "lodash": "^4.17.21",
16
+ "tslib": "^2.8.1"
7
17
  },
8
18
  "type": "commonjs",
9
19
  "main": "./src/index.js",
@@ -1,2 +1,3 @@
1
1
  export declare function AuthCombinedPublicAccessClassProtected(): ClassDecorator;
2
+ export declare function AuthCombinedAccessClassProtected(roles: string[]): ClassDecorator;
2
3
  export declare function AuthCombinedAdminAccessClassProtected(): ClassDecorator;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AuthCombinedPublicAccessClassProtected = AuthCombinedPublicAccessClassProtected;
4
+ exports.AuthCombinedAccessClassProtected = AuthCombinedAccessClassProtected;
4
5
  exports.AuthCombinedAdminAccessClassProtected = AuthCombinedAdminAccessClassProtected;
5
6
  const common_1 = require("@nestjs/common");
6
7
  const auth_constant_1 = require("../constants/auth.constant");
@@ -14,14 +15,18 @@ function AuthCombinedPublicAccessClassProtected() {
14
15
  (0, common_1.SetMetadata)(auth_constant_1.AUTH_ACCESS_FOR_META_KEY, [auth_enum_constant_1.ENUM_AUTH_ACCESS_FOR.USER])(constructor);
15
16
  };
16
17
  }
18
+ function AuthCombinedAccessClassProtected(roles) {
19
+ return function (constructor) {
20
+ // Applica UseGuards e SetMetadata a livello di classe
21
+ (0, common_1.UseGuards)(auth_combined_guard_1.CombinedAuthGuard, auth_payload_access_for_guard_1.AuthPayloadAccessForGuard)(constructor);
22
+ (0, common_1.SetMetadata)(auth_constant_1.AUTH_ACCESS_FOR_META_KEY, roles)(constructor);
23
+ };
24
+ }
17
25
  function AuthCombinedAdminAccessClassProtected() {
18
26
  return function (constructor) {
19
27
  // Applica UseGuards e SetMetadata a livello di classe
20
28
  (0, common_1.UseGuards)(auth_combined_guard_1.CombinedAuthGuard, auth_payload_access_for_guard_1.AuthPayloadAccessForGuard)(constructor);
21
- (0, common_1.SetMetadata)(auth_constant_1.AUTH_ACCESS_FOR_META_KEY, [
22
- auth_enum_constant_1.ENUM_AUTH_ACCESS_FOR.SUPER_ADMIN,
23
- auth_enum_constant_1.ENUM_AUTH_ACCESS_FOR.ADMIN,
24
- ])(constructor);
29
+ (0, common_1.SetMetadata)(auth_constant_1.AUTH_ACCESS_FOR_META_KEY, [auth_enum_constant_1.ENUM_AUTH_ACCESS_FOR.ADMIN])(constructor);
25
30
  };
26
31
  }
27
32
  //# sourceMappingURL=auth.combined.decorator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.combined.decorator.js","sourceRoot":"","sources":["../../../../../packages/authentication/src/decorators/auth.combined.decorator.ts"],"names":[],"mappings":";;AAMA,wFAQC;AAED,sFASC;AAzBD,2CAAwD;AACxD,8DAAsE;AACtE,wEAAuE;AACvE,gFAA2E;AAC3E,mGAA4F;AAE5F,SAAgB,sCAAsC;IACpD,OAAO,UAAU,WAAgB;QAC/B,sDAAsD;QACtD,IAAA,kBAAS,EAAC,uCAAiB,EAAE,yDAAyB,CAAC,CAAC,WAAW,CAAC,CAAC;QACrE,IAAA,oBAAW,EAAC,wCAAwB,EAAE,CAAC,yCAAoB,CAAC,IAAI,CAAC,CAAC,CAChE,WAAW,CACZ,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED,SAAgB,qCAAqC;IACnD,OAAO,UAAU,WAAgB;QAC/B,sDAAsD;QACtD,IAAA,kBAAS,EAAC,uCAAiB,EAAE,yDAAyB,CAAC,CAAC,WAAW,CAAC,CAAC;QACrE,IAAA,oBAAW,EAAC,wCAAwB,EAAE;YACpC,yCAAoB,CAAC,WAAW;YAChC,yCAAoB,CAAC,KAAK;SAC3B,CAAC,CAAC,WAAW,CAAC,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"auth.combined.decorator.js","sourceRoot":"","sources":["../../../../../packages/authentication/src/decorators/auth.combined.decorator.ts"],"names":[],"mappings":";;AAMA,wFAQC;AAED,4EAQC;AAED,sFAQC;AAlCD,2CAAwD;AACxD,8DAAsE;AACtE,wEAAuE;AACvE,gFAA2E;AAC3E,mGAA4F;AAE5F,SAAgB,sCAAsC;IACpD,OAAO,UAAU,WAAgB;QAC/B,sDAAsD;QACtD,IAAA,kBAAS,EAAC,uCAAiB,EAAE,yDAAyB,CAAC,CAAC,WAAW,CAAC,CAAC;QACrE,IAAA,oBAAW,EAAC,wCAAwB,EAAE,CAAC,yCAAoB,CAAC,IAAI,CAAC,CAAC,CAChE,WAAW,CACZ,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED,SAAgB,gCAAgC,CAC9C,KAAe;IAEf,OAAO,UAAU,WAAgB;QAC/B,sDAAsD;QACtD,IAAA,kBAAS,EAAC,uCAAiB,EAAE,yDAAyB,CAAC,CAAC,WAAW,CAAC,CAAC;QACrE,IAAA,oBAAW,EAAC,wCAAwB,EAAE,KAAK,CAAC,CAAC,WAAW,CAAC,CAAC;IAC5D,CAAC,CAAC;AACJ,CAAC;AAED,SAAgB,qCAAqC;IACnD,OAAO,UAAU,WAAgB;QAC/B,sDAAsD;QACtD,IAAA,kBAAS,EAAC,uCAAiB,EAAE,yDAAyB,CAAC,CAAC,WAAW,CAAC,CAAC;QACrE,IAAA,oBAAW,EAAC,wCAAwB,EAAE,CAAC,yCAAoB,CAAC,KAAK,CAAC,CAAC,CACjE,WAAW,CACZ,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -3,5 +3,9 @@ import { Reflector } from '@nestjs/core';
3
3
  export declare class AuthPayloadAccessForGuard implements CanActivate {
4
4
  private readonly reflector;
5
5
  constructor(reflector: Reflector);
6
+ /**
7
+ * Validate whether the current authenticated user can access
8
+ * a route based on the required access scope metadata.
9
+ */
6
10
  canActivate(context: ExecutionContext): Promise<boolean>;
7
11
  }
@@ -11,17 +11,27 @@ let AuthPayloadAccessForGuard = class AuthPayloadAccessForGuard {
11
11
  constructor(reflector) {
12
12
  this.reflector = reflector;
13
13
  }
14
+ /**
15
+ * Validate whether the current authenticated user can access
16
+ * a route based on the required access scope metadata.
17
+ */
14
18
  async canActivate(context) {
19
+ // Read required access scopes from handler/class metadata.
15
20
  const requiredFor = this.reflector.getAllAndOverride(constants_1.AUTH_ACCESS_FOR_META_KEY, [context.getHandler(), context.getClass()]);
21
+ // Extract current user's scope from request payload.
16
22
  const { user } = context.switchToHttp().getRequest();
17
23
  const { accessFor } = user;
24
+ // Allow if no scope is required or user is super admin.
18
25
  if (!requiredFor || accessFor === constants_1.ENUM_AUTH_ACCESS_FOR.SUPER_ADMIN) {
19
26
  return true;
20
27
  }
28
+ // Check whether user's scope matches one of required scopes.
21
29
  const hasFor = (0, lodash_1.includes)(requiredFor, accessFor);
30
+ // Deny with specific access-for error when scope does not match.
22
31
  if (!hasFor) {
23
32
  throw new errors_1.Api403AccessForError({ accessFor: accessFor });
24
33
  }
34
+ // Access granted.
25
35
  return true;
26
36
  }
27
37
  };
@@ -1 +1 @@
1
- {"version":3,"file":"auth.payload.access-for.guard.js","sourceRoot":"","sources":["../../../../../../packages/authentication/src/guards/payload/auth.payload.access-for.guard.ts"],"names":[],"mappings":";;;;AAAA,4CAAuD;AACvD,+CAGyB;AACzB,2CAA2E;AAC3E,uCAAyC;AACzC,mCAAkC;AAG3B,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IACpC,YAA6B,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAErD,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,MAAM,WAAW,GACf,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAC9B,oCAAwB,EACxB,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAC3C,CAAC;QAEJ,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QACrD,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAE3B,IAAI,CAAC,WAAW,IAAI,SAAS,KAAK,gCAAoB,CAAC,WAAW,EAAE,CAAC;YACnE,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,MAAM,GAAY,IAAA,iBAAQ,EAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAEzD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,6BAAoB,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;QAC3D,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAxBY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mBAAU,GAAE;6CAE6B,gBAAS;GADtC,yBAAyB,CAwBrC"}
1
+ {"version":3,"file":"auth.payload.access-for.guard.js","sourceRoot":"","sources":["../../../../../../packages/authentication/src/guards/payload/auth.payload.access-for.guard.ts"],"names":[],"mappings":";;;;AAAA,4CAAuD;AACvD,+CAGyB;AACzB,2CAA2E;AAC3E,uCAAyC;AACzC,mCAAkC;AAG3B,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IACpC,YAA6B,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAErD;;;OAGG;IACH,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,2DAA2D;QAC3D,MAAM,WAAW,GACf,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAC9B,oCAAwB,EACxB,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAC3C,CAAC;QAEJ,qDAAqD;QACrD,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QACrD,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAE3B,wDAAwD;QACxD,IAAI,CAAC,WAAW,IAAI,SAAS,KAAK,gCAAoB,CAAC,WAAW,EAAE,CAAC;YACnE,OAAO,IAAI,CAAC;QACd,CAAC;QAED,6DAA6D;QAC7D,MAAM,MAAM,GAAY,IAAA,iBAAQ,EAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAEzD,iEAAiE;QACjE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,6BAAoB,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;QAC3D,CAAC;QAED,kBAAkB;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAnCY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mBAAU,GAAE;6CAE6B,gBAAS;GADtC,yBAAyB,CAmCrC"}