@webiny/cognito 6.5.2-beta.2 → 6.5.2-beta.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.
@@ -1,13 +1,17 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { GetUserUseCase } from "@webiny/api-core/features/users/GetUser/index.js";
3
3
  import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
4
+ import { RolesRepository } from "@webiny/api-core/features/security/roles/shared/abstractions.js";
5
+ import { TeamsRepository } from "@webiny/api-core/features/security/teams/shared/abstractions.js";
4
6
  import { ResetUserMfaUseCase as UseCaseAbstraction } from "./abstractions.js";
5
7
  import { CognitoService } from "../CognitoService/abstractions.js";
6
8
  declare class ResetUserMfaUseCaseImpl implements UseCaseAbstraction.Interface {
7
9
  private identityContext;
8
10
  private cognitoService;
9
11
  private getUserUseCase;
10
- constructor(identityContext: IdentityContext.Interface, cognitoService: CognitoService.Interface, getUserUseCase: GetUserUseCase.Interface);
12
+ private rolesRepository;
13
+ private teamsRepository;
14
+ constructor(identityContext: IdentityContext.Interface, cognitoService: CognitoService.Interface, getUserUseCase: GetUserUseCase.Interface, rolesRepository: RolesRepository.Interface, teamsRepository: TeamsRepository.Interface);
11
15
  execute(id: string): Promise<Result<void, UseCaseAbstraction.Error>>;
12
16
  }
13
17
  export declare const ResetUserMfaUseCase: import("@webiny/di").Implementation<typeof ResetUserMfaUseCaseImpl>;
@@ -2,15 +2,21 @@ import { Result, createImplementation } from "@webiny/feature/api";
2
2
  import { GetUserUseCase } from "@webiny/api-core/features/users/GetUser/index.js";
3
3
  import { NotAuthorizedError } from "@webiny/api-core/features/users/shared/errors.js";
4
4
  import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
5
+ import { RolesRepository } from "@webiny/api-core/features/security/roles/shared/abstractions.js";
6
+ import { TeamsRepository } from "@webiny/api-core/features/security/teams/shared/abstractions.js";
7
+ import { canAssignRolesAndTeams } from "@webiny/api-core/features/security/utils/canAssignRolesAndTeams.js";
8
+ import { CANNOT_GRANT_PERMISSIONS_MESSAGE } from "@webiny/api-core/features/security/utils/canGrantPermissions.js";
5
9
  import { ResetUserMfaUseCase } from "./abstractions.js";
6
10
  import { Username } from "../../domain/Username.js";
7
11
  import { CognitoExternalUserError, CognitoResetMfaError } from "../../domain/errors.js";
8
12
  import { CognitoService } from "../CognitoService/abstractions.js";
9
13
  class ResetUserMfaUseCaseImpl {
10
- constructor(identityContext, cognitoService, getUserUseCase){
14
+ constructor(identityContext, cognitoService, getUserUseCase, rolesRepository, teamsRepository){
11
15
  this.identityContext = identityContext;
12
16
  this.cognitoService = cognitoService;
13
17
  this.getUserUseCase = getUserUseCase;
18
+ this.rolesRepository = rolesRepository;
19
+ this.teamsRepository = teamsRepository;
14
20
  }
15
21
  async execute(id) {
16
22
  const permission = await this.identityContext.getPermission("adminUsers.user");
@@ -21,6 +27,14 @@ class ResetUserMfaUseCaseImpl {
21
27
  if (getUserResult.isFail()) return Result.fail(getUserResult.error);
22
28
  const user = getUserResult.value;
23
29
  if (user.external) return Result.fail(new CognitoExternalUserError(id));
30
+ const canAssign = await canAssignRolesAndTeams({
31
+ identityContext: this.identityContext,
32
+ rolesRepository: this.rolesRepository,
33
+ teamsRepository: this.teamsRepository,
34
+ roles: user.roles ?? [],
35
+ teams: user.teams ?? []
36
+ });
37
+ if (!canAssign) return Result.fail(new NotAuthorizedError(CANNOT_GRANT_PERMISSIONS_MESSAGE));
24
38
  try {
25
39
  await this.cognitoService.resetMfa(Username.fromUser(user));
26
40
  return Result.ok();
@@ -35,7 +49,9 @@ const ResetUserMfaUseCase_ResetUserMfaUseCase = createImplementation({
35
49
  dependencies: [
36
50
  IdentityContext,
37
51
  CognitoService,
38
- GetUserUseCase
52
+ GetUserUseCase,
53
+ RolesRepository,
54
+ TeamsRepository
39
55
  ]
40
56
  });
41
57
  export { ResetUserMfaUseCase_ResetUserMfaUseCase as ResetUserMfaUseCase };
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/ResetUserMfa/ResetUserMfaUseCase.js","sources":["../../../../src/api/features/ResetUserMfa/ResetUserMfaUseCase.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { GetUserUseCase } from \"@webiny/api-core/features/users/GetUser/index.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/users/shared/errors.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { ResetUserMfaUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { Username } from \"~/api/domain/Username.js\";\nimport { CognitoExternalUserError, CognitoResetMfaError } from \"~/api/domain/errors.js\";\nimport { CognitoService } from \"../CognitoService/abstractions.js\";\n\nclass ResetUserMfaUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private cognitoService: CognitoService.Interface,\n private getUserUseCase: GetUserUseCase.Interface\n ) {}\n\n async execute(id: string): Promise<Result<void, UseCaseAbstraction.Error>> {\n const permission = await this.identityContext.getPermission(\"adminUsers.user\");\n if (!permission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const getUserResult = await this.getUserUseCase.execute({ id });\n if (getUserResult.isFail()) {\n return Result.fail(getUserResult.error);\n }\n\n const user = getUserResult.value;\n\n // A federated user signs in through their own identity provider, which handles their MFA.\n if (user.external) {\n return Result.fail(new CognitoExternalUserError(id));\n }\n\n // Unlike changing a shared account's name, email or password, any administrator of one of\n // the person's tenants may reset its MFA: the person can't do it themselves when they can't\n // sign in, and the reset doesn't give the administrator access to the account.\n try {\n await this.cognitoService.resetMfa(Username.fromUser(user));\n\n return Result.ok();\n } catch (cognitoError) {\n return Result.fail(new CognitoResetMfaError(cognitoError as Error));\n }\n }\n}\n\nexport const ResetUserMfaUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: ResetUserMfaUseCaseImpl,\n dependencies: [IdentityContext, CognitoService, GetUserUseCase]\n});\n"],"names":["ResetUserMfaUseCaseImpl","identityContext","cognitoService","getUserUseCase","id","permission","Result","NotAuthorizedError","getUserResult","user","CognitoExternalUserError","Username","cognitoError","CognitoResetMfaError","ResetUserMfaUseCase","createImplementation","UseCaseAbstraction","IdentityContext","CognitoService","GetUserUseCase"],"mappings":";;;;;;;;AAUA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,cAAwC,CAClD;aAHUF,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QAAQC,EAAU,EAAmD;QACvE,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC5D,IAAI,CAACA,YACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,gBAAgB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YAAEJ;QAAG;QAC7D,IAAII,cAAc,MAAM,IACpB,OAAOF,OAAO,IAAI,CAACE,cAAc,KAAK;QAG1C,MAAMC,OAAOD,cAAc,KAAK;QAGhC,IAAIC,KAAK,QAAQ,EACb,OAAOH,OAAO,IAAI,CAAC,IAAII,yBAAyBN;QAMpD,IAAI;YACA,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAACO,SAAS,QAAQ,CAACF;YAErD,OAAOH,OAAO,EAAE;QACpB,EAAE,OAAOM,cAAc;YACnB,OAAON,OAAO,IAAI,CAAC,IAAIO,qBAAqBD;QAChD;IACJ;AACJ;AAEO,MAAME,0CAAsBC,qBAAqB;IACpD,aAAaC;IACb,gBAAgBhB;IAChB,cAAc;QAACiB;QAAiBC;QAAgBC;KAAe;AACnE"}
1
+ {"version":3,"file":"api/features/ResetUserMfa/ResetUserMfaUseCase.js","sources":["../../../../src/api/features/ResetUserMfa/ResetUserMfaUseCase.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { GetUserUseCase } from \"@webiny/api-core/features/users/GetUser/index.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/users/shared/errors.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { RolesRepository } from \"@webiny/api-core/features/security/roles/shared/abstractions.js\";\nimport { TeamsRepository } from \"@webiny/api-core/features/security/teams/shared/abstractions.js\";\nimport { canAssignRolesAndTeams } from \"@webiny/api-core/features/security/utils/canAssignRolesAndTeams.js\";\nimport { CANNOT_GRANT_PERMISSIONS_MESSAGE } from \"@webiny/api-core/features/security/utils/canGrantPermissions.js\";\nimport { ResetUserMfaUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { Username } from \"~/api/domain/Username.js\";\nimport { CognitoExternalUserError, CognitoResetMfaError } from \"~/api/domain/errors.js\";\nimport { CognitoService } from \"../CognitoService/abstractions.js\";\n\nclass ResetUserMfaUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private cognitoService: CognitoService.Interface,\n private getUserUseCase: GetUserUseCase.Interface,\n private rolesRepository: RolesRepository.Interface,\n private teamsRepository: TeamsRepository.Interface\n ) {}\n\n async execute(id: string): Promise<Result<void, UseCaseAbstraction.Error>> {\n const permission = await this.identityContext.getPermission(\"adminUsers.user\");\n if (!permission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const getUserResult = await this.getUserUseCase.execute({ id });\n if (getUserResult.isFail()) {\n return Result.fail(getUserResult.error);\n }\n\n const user = getUserResult.value;\n\n // A federated user signs in through their own identity provider, which handles their MFA.\n if (user.external) {\n return Result.fail(new CognitoExternalUserError(id));\n }\n\n // Security: the caller may only manage a user whose roles and teams they could assign\n // (same rule as updating or deleting a user).\n const canAssign = await canAssignRolesAndTeams({\n identityContext: this.identityContext,\n rolesRepository: this.rolesRepository,\n teamsRepository: this.teamsRepository,\n roles: user.roles ?? [],\n teams: user.teams ?? []\n });\n if (!canAssign) {\n return Result.fail(new NotAuthorizedError(CANNOT_GRANT_PERMISSIONS_MESSAGE));\n }\n\n // Unlike changing a shared account's name, email or password, any administrator of one of\n // the person's tenants who may manage the user there may reset its MFA: the person can't\n // do it themselves when they can't sign in, and the reset doesn't give the administrator\n // access to the account.\n try {\n await this.cognitoService.resetMfa(Username.fromUser(user));\n\n return Result.ok();\n } catch (cognitoError) {\n return Result.fail(new CognitoResetMfaError(cognitoError as Error));\n }\n }\n}\n\nexport const ResetUserMfaUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: ResetUserMfaUseCaseImpl,\n dependencies: [\n IdentityContext,\n CognitoService,\n GetUserUseCase,\n RolesRepository,\n TeamsRepository\n ]\n});\n"],"names":["ResetUserMfaUseCaseImpl","identityContext","cognitoService","getUserUseCase","rolesRepository","teamsRepository","id","permission","Result","NotAuthorizedError","getUserResult","user","CognitoExternalUserError","canAssign","canAssignRolesAndTeams","CANNOT_GRANT_PERMISSIONS_MESSAGE","Username","cognitoError","CognitoResetMfaError","ResetUserMfaUseCase","createImplementation","UseCaseAbstraction","IdentityContext","CognitoService","GetUserUseCase","RolesRepository","TeamsRepository"],"mappings":";;;;;;;;;;;;AAcA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,cAAwC,EACxCC,eAA0C,EAC1CC,eAA0C,CACpD;aALUJ,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,cAAc,GAAdA;aACAC,eAAe,GAAfA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QAAQC,EAAU,EAAmD;QACvE,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC5D,IAAI,CAACA,YACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,gBAAgB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YAAEJ;QAAG;QAC7D,IAAII,cAAc,MAAM,IACpB,OAAOF,OAAO,IAAI,CAACE,cAAc,KAAK;QAG1C,MAAMC,OAAOD,cAAc,KAAK;QAGhC,IAAIC,KAAK,QAAQ,EACb,OAAOH,OAAO,IAAI,CAAC,IAAII,yBAAyBN;QAKpD,MAAMO,YAAY,MAAMC,uBAAuB;YAC3C,iBAAiB,IAAI,CAAC,eAAe;YACrC,iBAAiB,IAAI,CAAC,eAAe;YACrC,iBAAiB,IAAI,CAAC,eAAe;YACrC,OAAOH,KAAK,KAAK,IAAI,EAAE;YACvB,OAAOA,KAAK,KAAK,IAAI,EAAE;QAC3B;QACA,IAAI,CAACE,WACD,OAAOL,OAAO,IAAI,CAAC,IAAIC,mBAAmBM;QAO9C,IAAI;YACA,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAACC,SAAS,QAAQ,CAACL;YAErD,OAAOH,OAAO,EAAE;QACpB,EAAE,OAAOS,cAAc;YACnB,OAAOT,OAAO,IAAI,CAAC,IAAIU,qBAAqBD;QAChD;IACJ;AACJ;AAEO,MAAME,0CAAsBC,qBAAqB;IACpD,aAAaC;IACb,gBAAgBrB;IAChB,cAAc;QACVsB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/cognito",
3
- "version": "6.5.2-beta.2",
3
+ "version": "6.5.2-beta.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
@@ -15,20 +15,20 @@
15
15
  "dependencies": {
16
16
  "@smithy/signature-v4": "5.7.5",
17
17
  "@smithy/types": "4.20.0",
18
- "@webiny/admin-ui": "6.5.2-beta.2",
19
- "@webiny/api-core": "6.5.2-beta.2",
20
- "@webiny/app": "6.5.2-beta.2",
21
- "@webiny/app-admin": "6.5.2-beta.2",
22
- "@webiny/aws-sdk": "6.5.2-beta.2",
18
+ "@webiny/admin-ui": "6.5.2-beta.3",
19
+ "@webiny/api-core": "6.5.2-beta.3",
20
+ "@webiny/app": "6.5.2-beta.3",
21
+ "@webiny/app-admin": "6.5.2-beta.3",
22
+ "@webiny/aws-sdk": "6.5.2-beta.3",
23
23
  "@webiny/di": "1.1.0",
24
- "@webiny/feature": "6.5.2-beta.2",
25
- "@webiny/form": "6.5.2-beta.2",
26
- "@webiny/handler-graphql": "6.5.2-beta.2",
27
- "@webiny/icons": "6.5.2-beta.2",
28
- "@webiny/project": "6.5.2-beta.2",
29
- "@webiny/project-aws": "6.5.2-beta.2",
30
- "@webiny/react-properties": "6.5.2-beta.2",
31
- "@webiny/validation": "6.5.2-beta.2",
24
+ "@webiny/feature": "6.5.2-beta.3",
25
+ "@webiny/form": "6.5.2-beta.3",
26
+ "@webiny/handler-graphql": "6.5.2-beta.3",
27
+ "@webiny/icons": "6.5.2-beta.3",
28
+ "@webiny/project": "6.5.2-beta.3",
29
+ "@webiny/project-aws": "6.5.2-beta.3",
30
+ "@webiny/react-properties": "6.5.2-beta.3",
31
+ "@webiny/validation": "6.5.2-beta.3",
32
32
  "aws-amplify": "6.22.2",
33
33
  "graphql": "16.15.0",
34
34
  "jsonwebtoken": "9.0.3",
@@ -41,9 +41,9 @@
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/react": "18.3.31",
44
- "@webiny/build-tools": "6.5.2-beta.2",
45
- "@webiny/project-utils": "6.5.2-beta.2",
46
- "@webiny/wcp": "6.5.2-beta.2",
44
+ "@webiny/build-tools": "6.5.2-beta.3",
45
+ "@webiny/project-utils": "6.5.2-beta.3",
46
+ "@webiny/wcp": "6.5.2-beta.3",
47
47
  "vitest": "5.1.0"
48
48
  },
49
49
  "publishConfig": {