@vcita/oauth-client-nestjs 1.16.1 → 1.17.3

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 CHANGED
@@ -6,7 +6,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## 1.17.3 (2021-12-06)
10
+ ### Fixed
11
+ - `ActorEntity` class `getActingAs` now also returns the direct actor if he's not acting as anyone else
9
12
 
13
+ ## 1.17.2 (2021-12-05)
14
+ ### Added
15
+ - Added the ability to mock the `AuthorizationPayloadEntity` object for testing purposes
16
+ Added the option to mock the oauth process for e2e tests by adding to the `setup.ts` file
17
+ this mockTesters `[new OauthMocker()]`
18
+
19
+ ## 1.17.1 (2021-12-02)
20
+ ### Fixed
21
+ - `AuthorizationPayloadEntity` now properly exported.
22
+
23
+ ## 1.17.0 (2021-12-02)
24
+ ### Added
25
+ - Support for `belongs` claim
26
+ - New optional attribute for `ActorEntity` class, `belongTo` with methods for fetching specific entity types.
27
+ This property holds the information about the relations of the acting entity (the one who initiated the request)
28
+
29
+ ## 1.16.1 (2021-11-30)
30
+ ### Changes
31
+ - Auth middleware now verify authentication only with cookies (and does not compare it to query params).
32
+ _Note:_ That flow applies to application only
33
+
34
+ ## 1.16.0 (2021-11-28)
10
35
  ### Changes
11
36
  - AuthorizationPayloadEntity constructor has been changed (using new syntax)
12
37
  - Parsing actor from JWT token has been changed. now supports:
package/dist/index.d.ts CHANGED
@@ -9,4 +9,5 @@ export * from './oauth/interfaces/oauth.interface';
9
9
  export * from './oauth/repositories/oauth-data.entity';
10
10
  export * from './oauth/enums/actors.enum';
11
11
  export * from './oauth/repositories/actor.entity';
12
+ export * from './oauth/repositories/authorization-payload.entity';
12
13
  export * from './oauth/decorators/authorization.decorator';
package/dist/index.js CHANGED
@@ -21,5 +21,6 @@ __exportStar(require("./oauth/interfaces/oauth.interface"), exports);
21
21
  __exportStar(require("./oauth/repositories/oauth-data.entity"), exports);
22
22
  __exportStar(require("./oauth/enums/actors.enum"), exports);
23
23
  __exportStar(require("./oauth/repositories/actor.entity"), exports);
24
+ __exportStar(require("./oauth/repositories/authorization-payload.entity"), exports);
24
25
  __exportStar(require("./oauth/decorators/authorization.decorator"), exports);
25
26
  //# 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,uDAAqC;AACrC,uEAAqD;AACrD,sEAAoD;AACpD,iEAA+C;AAC/C,0EAAwD;AACxD,0EAAwD;AACxD,uEAAqD;AACrD,qEAAmD;AACnD,yEAAuD;AACvD,4DAA0C;AAC1C,oEAAkD;AAClD,6EAA2D"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAqC;AACrC,uEAAqD;AACrD,sEAAoD;AACpD,iEAA+C;AAC/C,0EAAwD;AACxD,0EAAwD;AACxD,uEAAqD;AACrD,qEAAmD;AACnD,yEAAuD;AACvD,4DAA0C;AAC1C,oEAAkD;AAClD,oFAAkE;AAClE,6EAA2D"}
@@ -4,5 +4,6 @@ export declare enum ActorType {
4
4
  USER = "user",
5
5
  DIRECTORY = "directory",
6
6
  BUSINESS = "business",
7
- STAFF = "staff"
7
+ STAFF = "staff",
8
+ CLIENT = "client"
8
9
  }
@@ -9,5 +9,6 @@ var ActorType;
9
9
  ActorType["DIRECTORY"] = "directory";
10
10
  ActorType["BUSINESS"] = "business";
11
11
  ActorType["STAFF"] = "staff";
12
+ ActorType["CLIENT"] = "client";
12
13
  })(ActorType = exports.ActorType || (exports.ActorType = {}));
13
14
  //# sourceMappingURL=actors.enum.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"actors.enum.js","sourceRoot":"","sources":["../../../src/oauth/enums/actors.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,wBAAW,CAAA;IACX,0BAAa,CAAA;IACb,oCAAuB,CAAA;IACvB,kCAAqB,CAAA;IACrB,4BAAe,CAAA;AACjB,CAAC,EAPW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAOpB"}
1
+ {"version":3,"file":"actors.enum.js","sourceRoot":"","sources":["../../../src/oauth/enums/actors.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAQX;AARD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,wBAAW,CAAA;IACX,0BAAa,CAAA;IACb,oCAAuB,CAAA;IACvB,kCAAqB,CAAA;IACrB,4BAAe,CAAA;IACf,8BAAiB,CAAA;AACnB,CAAC,EARW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAQpB"}
@@ -1,9 +1,30 @@
1
1
  import { ActorType } from '../enums/actors.enum';
2
- export declare class ActorEntity {
2
+ interface ActorBase {
3
+ uid: string;
4
+ type: ActorType;
5
+ }
6
+ interface Belongs extends ActorBase {
7
+ belongsTo?: BelongsEntity;
8
+ }
9
+ interface Acts extends ActorBase {
10
+ actingAs?: BelongsEntity;
11
+ }
12
+ export declare class BelongsEntity implements Belongs {
13
+ readonly uid: string;
14
+ readonly type: ActorType;
15
+ readonly belongsTo?: BelongsEntity;
16
+ constructor(uid: string, type: ActorType, belongsTo?: BelongsEntity);
17
+ isBelongTo(): boolean;
18
+ getBelongTo(type: ActorType): BelongsEntity | null;
19
+ }
20
+ export declare class ActorEntity extends BelongsEntity implements Acts {
3
21
  readonly uid: string;
4
22
  readonly type: ActorType;
5
- actingAs?: ActorEntity;
6
- constructor(uid: string, type: ActorType, actingAs?: ActorEntity);
23
+ readonly belongsTo?: BelongsEntity;
24
+ readonly actingAs?: BelongsEntity;
25
+ constructor(uid: string, type: ActorType, belongsTo?: BelongsEntity, actingAs?: BelongsEntity);
26
+ private getBusinessUid;
7
27
  isActingAs(): boolean;
8
- getActingAs(type: ActorType): ActorEntity | null;
28
+ getActingAs(type: ActorType): BelongsEntity | null;
9
29
  }
30
+ export {};
@@ -1,21 +1,49 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ActorEntity = void 0;
4
- class ActorEntity {
5
- constructor(uid, type, actingAs) {
3
+ exports.ActorEntity = exports.BelongsEntity = void 0;
4
+ const actors_enum_1 = require("../enums/actors.enum");
5
+ class BelongsEntity {
6
+ constructor(uid, type, belongsTo) {
6
7
  this.uid = uid;
7
8
  this.type = type;
9
+ this.belongsTo = belongsTo;
10
+ }
11
+ isBelongTo() {
12
+ return Boolean(this.belongsTo);
13
+ }
14
+ getBelongTo(type) {
15
+ let curBelongsTo = this.belongsTo;
16
+ while (curBelongsTo) {
17
+ if (curBelongsTo.type === type)
18
+ return curBelongsTo;
19
+ curBelongsTo = curBelongsTo.belongsTo;
20
+ }
21
+ return null;
22
+ }
23
+ }
24
+ exports.BelongsEntity = BelongsEntity;
25
+ class ActorEntity extends BelongsEntity {
26
+ constructor(uid, type, belongsTo, actingAs) {
27
+ super(uid, type, belongsTo);
28
+ this.uid = uid;
29
+ this.type = type;
30
+ this.belongsTo = belongsTo;
8
31
  this.actingAs = actingAs;
9
32
  }
33
+ getBusinessUid() {
34
+ return this.getActingAs(actors_enum_1.ActorType.STAFF).getBelongTo(actors_enum_1.ActorType.BUSINESS).uid;
35
+ }
10
36
  isActingAs() {
11
37
  return Boolean(this.actingAs);
12
38
  }
13
39
  getActingAs(type) {
40
+ if (!this.actingAs && this.type === type)
41
+ return this;
14
42
  let curActingAs = this.actingAs;
15
43
  while (curActingAs) {
16
44
  if (curActingAs.type === type)
17
45
  return curActingAs;
18
- curActingAs = curActingAs.actingAs;
46
+ curActingAs = curActingAs.belongsTo;
19
47
  }
20
48
  return null;
21
49
  }
@@ -1 +1 @@
1
- {"version":3,"file":"actor.entity.js","sourceRoot":"","sources":["../../../src/oauth/repositories/actor.entity.ts"],"names":[],"mappings":";;;AAEA,MAAa,WAAW;IACtB,YACkB,GAAW,EACX,IAAe,EACxB,QAAsB;QAFb,QAAG,GAAH,GAAG,CAAQ;QACX,SAAI,GAAJ,IAAI,CAAW;QACxB,aAAQ,GAAR,QAAQ,CAAc;IAC5B,CAAC;IAEJ,UAAU;QACR,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAED,WAAW,CAAC,IAAe;QACzB,IAAI,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC;QAEhC,OAAO,WAAW,EAAE;YAClB,IAAI,WAAW,CAAC,IAAI,KAAK,IAAI;gBAAE,OAAO,WAAW,CAAC;YAClD,WAAW,GAAG,WAAW,CAAC,QAAQ,CAAC;SACpC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AArBD,kCAqBC"}
1
+ {"version":3,"file":"actor.entity.js","sourceRoot":"","sources":["../../../src/oauth/repositories/actor.entity.ts"],"names":[],"mappings":";;;AAEA,sDAAiD;AAejD,MAAa,aAAa;IACxB,YACW,GAAW,EACX,IAAe,EACf,SAAyB;QAFzB,QAAG,GAAH,GAAG,CAAQ;QACX,SAAI,GAAJ,IAAI,CAAW;QACf,cAAS,GAAT,SAAS,CAAgB;IACjC,CAAC;IAEJ,UAAU;QACR,OAAO,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACjC,CAAC;IAED,WAAW,CAAC,IAAe;QACzB,IAAI,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC;QAElC,OAAO,YAAY,EAAE;YACnB,IAAI,YAAY,CAAC,IAAI,KAAK,IAAI;gBAAE,OAAO,YAAY,CAAC;YACpD,YAAY,GAAG,YAAY,CAAC,SAAS,CAAC;SACvC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AArBD,sCAqBC;AAED,MAAa,WAAY,SAAQ,aAAa;IAC5C,YACkB,GAAW,EACX,IAAe,EACf,SAAyB,EACzB,QAAwB;QAExC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;QALZ,QAAG,GAAH,GAAG,CAAQ;QACX,SAAI,GAAJ,IAAI,CAAW;QACf,cAAS,GAAT,SAAS,CAAgB;QACzB,aAAQ,GAAR,QAAQ,CAAgB;IAG1C,CAAC;IAEO,cAAc;QAEpB,OAAO,IAAI,CAAC,WAAW,CAAC,uBAAS,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,uBAAS,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC;IAC/E,CAAC;IAED,UAAU;QACR,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAED,WAAW,CAAC,IAAe;QACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QAEtD,IAAI,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC;QAEhC,OAAO,WAAW,EAAE;YAClB,IAAI,WAAW,CAAC,IAAI,KAAK,IAAI;gBAAE,OAAO,WAAW,CAAC;YAClD,WAAW,GAAG,WAAW,CAAC,SAAS,CAAC;SACrC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA/BD,kCA+BC"}
@@ -0,0 +1,3 @@
1
+ import { AuthorizationPayloadEntity } from '../..';
2
+ export declare function MockDefaultStaffAuthorization(): AuthorizationPayloadEntity;
3
+ export declare function MockStaffAuthorization(business_uid: any, staff_uid: any): AuthorizationPayloadEntity;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockStaffAuthorization = exports.MockDefaultStaffAuthorization = void 0;
4
+ const __1 = require("../..");
5
+ function MockDefaultStaffAuthorization() {
6
+ return MockStaffAuthorization('business_1111', 'staff_1111');
7
+ }
8
+ exports.MockDefaultStaffAuthorization = MockDefaultStaffAuthorization;
9
+ function MockStaffAuthorization(business_uid, staff_uid) {
10
+ const belongsBusiness = new __1.BelongsEntity(business_uid, __1.ActorType.BUSINESS);
11
+ const actorStaff = new __1.ActorEntity(staff_uid, __1.ActorType.STAFF, belongsBusiness);
12
+ return new __1.AuthorizationPayloadEntity(null, actorStaff);
13
+ }
14
+ exports.MockStaffAuthorization = MockStaffAuthorization;
15
+ //# sourceMappingURL=mock-oauth.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-oauth.dto.js","sourceRoot":"","sources":["../../../src/oauth/tests/mock-oauth.dto.ts"],"names":[],"mappings":";;;AAAA,6BAKe;AAEf,SAAgB,6BAA6B;IAC3C,OAAO,sBAAsB,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;AAC/D,CAAC;AAFD,sEAEC;AAED,SAAgB,sBAAsB,CAAC,YAAY,EAAE,SAAS;IAC5D,MAAM,eAAe,GAAG,IAAI,iBAAa,CAAC,YAAY,EAAE,aAAS,CAAC,QAAQ,CAAC,CAAC;IAC5E,MAAM,UAAU,GAAG,IAAI,eAAW,CAAC,SAAS,EAAE,aAAS,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;IAChF,OAAO,IAAI,8BAA0B,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AAC1D,CAAC;AAJD,wDAIC"}
@@ -0,0 +1,11 @@
1
+ import { NestMiddleware } from '@nestjs/common';
2
+ import { Request } from 'express';
3
+ import { ActorEntity, BelongsEntity } from '../..';
4
+ export declare class MockAuthMiddleware implements NestMiddleware {
5
+ use(req: Request, res: Response, next: () => void): Promise<void>;
6
+ static to_actor(actor: any): ActorEntity;
7
+ static to_belongs(belongs: any): BelongsEntity;
8
+ }
9
+ export declare class MockOauthService {
10
+ isConnected(): Promise<boolean>;
11
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockOauthService = exports.MockAuthMiddleware = void 0;
4
+ const __1 = require("../..");
5
+ const auth_enum_1 = require("../enums/auth.enum");
6
+ class MockAuthMiddleware {
7
+ async use(req, res, next) {
8
+ const authorizationHeader = req.get('Authorization');
9
+ if (authorizationHeader == null)
10
+ return next();
11
+ const authObject = JSON.parse(authorizationHeader.replace('Bearer ', ''));
12
+ const auth = new __1.AuthorizationPayloadEntity(null, MockAuthMiddleware.to_actor(authObject.actor));
13
+ req[auth_enum_1.authActorHeader] = auth;
14
+ next();
15
+ }
16
+ static to_actor(actor) {
17
+ return new __1.ActorEntity(actor.uid, actor.type, MockAuthMiddleware.to_belongs(actor.belongsTo), MockAuthMiddleware.to_belongs(actor.actingAs));
18
+ }
19
+ static to_belongs(belongs) {
20
+ if (belongs == null)
21
+ return null;
22
+ return new __1.BelongsEntity(belongs.uid, belongs.type, MockAuthMiddleware.to_belongs(belongs.belongsTo));
23
+ }
24
+ }
25
+ exports.MockAuthMiddleware = MockAuthMiddleware;
26
+ class MockOauthService {
27
+ async isConnected() {
28
+ return true;
29
+ }
30
+ }
31
+ exports.MockOauthService = MockOauthService;
32
+ //# sourceMappingURL=mock-oauth.middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-oauth.middleware.js","sourceRoot":"","sources":["../../../src/oauth/tests/mock-oauth.middleware.ts"],"names":[],"mappings":";;;AAEA,6BAA+E;AAC/E,kDAAqD;AAErD,MAAa,kBAAkB;IAC7B,KAAK,CAAC,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAgB;QACrD,MAAM,mBAAmB,GAAG,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QACrD,IAAI,mBAAmB,IAAI,IAAI;YAAE,OAAO,IAAI,EAAE,CAAC;QAE/C,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;QAC1E,MAAM,IAAI,GAA+B,IAAI,8BAA0B,CACrE,IAAI,EACJ,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAC9C,CAAC;QACF,GAAG,CAAC,2BAAe,CAAC,GAAG,IAAI,CAAC;QAC5B,IAAI,EAAE,CAAC;IACT,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,KAAK;QACnB,OAAO,IAAI,eAAW,CACpB,KAAK,CAAC,GAAG,EACT,KAAK,CAAC,IAAI,EACV,kBAAkB,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,EAC9C,kBAAkB,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,CAC9C,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,OAAO;QACvB,IAAI,OAAO,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;QACjC,OAAO,IAAI,iBAAa,CACtB,OAAO,CAAC,GAAG,EACX,OAAO,CAAC,IAAI,EACZ,kBAAkB,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,CACjD,CAAC;IACJ,CAAC;CACF;AA/BD,gDA+BC;AAED,MAAa,gBAAgB;IAC3B,KAAK,CAAC,WAAW;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAJD,4CAIC"}
@@ -0,0 +1,7 @@
1
+ import { TestingModuleBuilder } from '@nestjs/testing';
2
+ import { INestApplication } from '@nestjs/common';
3
+ import { SetupMocker } from '@vcita/infra-nestjs/dist/infra/tests/setup-mocker';
4
+ export declare class OauthMocker implements SetupMocker {
5
+ mockBuilder(builder: TestingModuleBuilder): TestingModuleBuilder;
6
+ mockApp(app: INestApplication): void;
7
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OauthMocker = void 0;
4
+ const __1 = require("../..");
5
+ const mock_oauth_middleware_1 = require("./mock-oauth.middleware");
6
+ class OauthMocker {
7
+ mockBuilder(builder) {
8
+ return builder.overrideProvider(__1.OauthService).useClass(mock_oauth_middleware_1.MockOauthService);
9
+ }
10
+ mockApp(app) {
11
+ app.use(new mock_oauth_middleware_1.MockAuthMiddleware().use);
12
+ }
13
+ }
14
+ exports.OauthMocker = OauthMocker;
15
+ //# sourceMappingURL=oauth-mocker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-mocker.js","sourceRoot":"","sources":["../../../src/oauth/tests/oauth-mocker.ts"],"names":[],"mappings":";;;AAEA,6BAAqC;AACrC,mEAA+E;AAG/E,MAAa,WAAW;IACtB,WAAW,CAAC,OAA6B;QACvC,OAAO,OAAO,CAAC,gBAAgB,CAAC,gBAAY,CAAC,CAAC,QAAQ,CAAC,wCAAgB,CAAC,CAAA;IAC1E,CAAC;IAED,OAAO,CAAC,GAAqB;QAC3B,GAAG,CAAC,GAAG,CAAC,IAAI,0CAAkB,EAAE,CAAC,GAAG,CAAC,CAAC;IACxC,CAAC;CACF;AARD,kCAQC"}
@@ -1,7 +1,7 @@
1
1
  import { Algorithm, JwtPayload, SignOptions, VerifyCallback, VerifyOptions } from 'jsonwebtoken';
2
2
  import { Request } from 'express';
3
3
  import { AuthorizationPayloadEntity } from '../repositories/authorization-payload.entity';
4
- import { ActorEntity } from '../repositories/actor.entity';
4
+ import { BelongsEntity } from '../repositories/actor.entity';
5
5
  import { ActorType } from '../enums/actors.enum';
6
6
  export declare class AuthenticationUtils {
7
7
  static ALGORITHM: Algorithm;
@@ -23,8 +23,9 @@ export declare class AuthenticationUtils {
23
23
  }, ttl?: number): JwtPayload;
24
24
  private static getBaseClaims;
25
25
  static parseActorFromPayload(payload: JwtPayload): AuthorizationPayloadEntity;
26
- static parseClaim<ClaimDataType, ClaimParsedValue>(claim: ClaimDataType, parser: (claim: ClaimDataType) => ClaimParsedValue, claimNotPresent?: () => ClaimParsedValue | undefined, badClaim?: () => ClaimParsedValue | undefined): ClaimParsedValue;
26
+ static parseClaim<ClaimDataType, ClaimParsedValue>(claim: ClaimDataType, parser: (claim: ClaimDataType) => ClaimParsedValue, claimNotPresent?: () => ClaimParsedValue | null, badClaim?: () => ClaimParsedValue | null): ClaimParsedValue;
27
27
  static parseIssuer(issClaim: string): [string, ActorType];
28
- static parseSubjects(subClaim: string | undefined): ActorEntity;
28
+ static parseSubjects(subClaim: string): BelongsEntity;
29
+ static parseBelongs(belongsClaim: string | undefined): BelongsEntity;
29
30
  private static extractEntityUidAndType;
30
31
  }
@@ -66,10 +66,11 @@ class AuthenticationUtils {
66
66
  throw new common_1.UnauthorizedException('Bad JWT received, no [ scp ] claim');
67
67
  });
68
68
  const [iss_uid, iss_type] = AuthenticationUtils.parseClaim(payload.iss, AuthenticationUtils.parseIssuer, () => { throw new common_1.UnauthorizedException('Bad JWT received, no [ iss ] claim'); });
69
- const subjects = AuthenticationUtils.parseClaim(payload.sub, AuthenticationUtils.parseSubjects);
70
- return new authorization_payload_entity_1.AuthorizationPayloadEntity(scopes, new actor_entity_1.ActorEntity(iss_uid, iss_type, subjects));
69
+ const belongsTo = AuthenticationUtils.parseClaim(payload.belongs, AuthenticationUtils.parseBelongs);
70
+ const actingAs = AuthenticationUtils.parseClaim(payload.sub, AuthenticationUtils.parseSubjects);
71
+ return new authorization_payload_entity_1.AuthorizationPayloadEntity(scopes, new actor_entity_1.ActorEntity(iss_uid, iss_type, belongsTo, actingAs));
71
72
  }
72
- static parseClaim(claim, parser, claimNotPresent = () => undefined, badClaim) {
73
+ static parseClaim(claim, parser, claimNotPresent = () => null, badClaim) {
73
74
  if (!claim)
74
75
  return claimNotPresent();
75
76
  try {
@@ -87,13 +88,15 @@ class AuthenticationUtils {
87
88
  static parseSubjects(subClaim) {
88
89
  const hierarchy = subClaim
89
90
  .split(';')
90
- .map((entity) => new actor_entity_1.ActorEntity(...AuthenticationUtils.extractEntityUidAndType(entity)));
91
- const topLevelEntity = hierarchy.shift();
92
- let currentEntity = (topLevelEntity.actingAs = hierarchy.shift());
91
+ .map((entity) => AuthenticationUtils.extractEntityUidAndType(entity));
92
+ let currentEntity = new actor_entity_1.BelongsEntity(...hierarchy.pop());
93
93
  while (hierarchy.length) {
94
- currentEntity = currentEntity.actingAs = hierarchy.shift();
94
+ currentEntity = new actor_entity_1.BelongsEntity(...hierarchy.pop(), currentEntity);
95
95
  }
96
- return topLevelEntity;
96
+ return currentEntity;
97
+ }
98
+ static parseBelongs(belongsClaim) {
99
+ return AuthenticationUtils.parseSubjects(belongsClaim);
97
100
  }
98
101
  static extractEntityUidAndType(entity) {
99
102
  const [id, type] = entity.split(':');
@@ -1 +1 @@
1
- {"version":3,"file":"authentication.utils.js","sourceRoot":"","sources":["../../../src/oauth/utils/authentication.utils.ts"],"names":[],"mappings":";;;AAAA,+CAQsB;AAEtB,uFAAgF;AAChF,+FAA0F;AAC1F,kDAAqE;AACrE,+DAA2D;AAC3D,sDAAiD;AACjD,2CAAuD;AAEvD,MAAa,mBAAmB;IAI9B,MAAM,CAAC,MAAM,CAAC,KAAa,EAAE,QAAwB;QACnD,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,IAAA,qBAAM,EAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,gBAAgB,EAAE,EAAE,QAAQ,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,CAAC,uBAAuB,CAAC,GAAY;QACzC,IAAI,KAAK,CAAC;QACV,MAAM,mBAAmB,GAAG,GAAG,CAAC,GAAG,CAAC,+BAAmB,CAAC,iBAAiB,CAAC,CAAC;QAC3E,IAAI,mBAAmB,IAAI,mBAAmB,CAAC,UAAU,CAAC,sBAAU,CAAC,MAAM,CAAC,EAAE;YAC5E,KAAK,GAAG,mBAAmB,CAAC,OAAO,CAAC,GAAG,sBAAU,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC,CAAC;SAClE;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,kBAAkB,CAAC,OAAmB;QAE3C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,YAAY;QACjB,OAAO,IAAA,uBAAa,GAAE,CAAC,qBAAqB,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,gBAAgB;QACrB,OAAO,EAAE,UAAU,EAAE,IA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