@webiny/cognito 6.6.0-alpha.11 → 6.6.0-alpha.13

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 (103) hide show
  1. package/admin/Cognito.js +7 -1
  2. package/admin/Cognito.js.map +1 -1
  3. package/admin/presentation/Cognito/CognitoLoginScreen.js +9 -1
  4. package/admin/presentation/Cognito/CognitoLoginScreen.js.map +1 -1
  5. package/admin/presentation/Cognito/CognitoPresenter.d.ts +10 -1
  6. package/admin/presentation/Cognito/CognitoPresenter.js +50 -4
  7. package/admin/presentation/Cognito/CognitoPresenter.js.map +1 -1
  8. package/admin/presentation/Cognito/CognitoPresenter.test.d.ts +1 -0
  9. package/admin/presentation/Cognito/CognitoPresenter.test.js +180 -0
  10. package/admin/presentation/Cognito/CognitoPresenter.test.js.map +1 -0
  11. package/admin/presentation/Cognito/abstractions.d.ts +8 -1
  12. package/admin/presentation/Cognito/abstractions.js.map +1 -1
  13. package/admin/presentation/Cognito/components/FederatedProviders.js +1 -1
  14. package/admin/presentation/Cognito/components/FederatedProviders.js.map +1 -1
  15. package/admin/presentation/Cognito/components/NoTenantAccess.d.ts +23 -0
  16. package/admin/presentation/Cognito/components/NoTenantAccess.js +10 -0
  17. package/admin/presentation/Cognito/components/NoTenantAccess.js.map +1 -0
  18. package/admin/presentation/Cognito/components/SelectTenant.d.ts +26 -0
  19. package/admin/presentation/Cognito/components/SelectTenant.js +15 -0
  20. package/admin/presentation/Cognito/components/SelectTenant.js.map +1 -0
  21. package/admin/presentation/Cognito/components/SetNewPassword.js.map +1 -1
  22. package/admin/presentation/Cognito/components/SetupTotp.js +6 -5
  23. package/admin/presentation/Cognito/components/SetupTotp.js.map +1 -1
  24. package/admin/presentation/Cognito/components/View.js +5 -5
  25. package/admin/presentation/Cognito/components/View.js.map +1 -1
  26. package/admin/presentation/Cognito/components/index.d.ts +38 -0
  27. package/admin/presentation/Cognito/components/index.js +4 -0
  28. package/admin/presentation/Cognito/components/index.js.map +1 -1
  29. package/api/CognitoApiFeature.js +6 -0
  30. package/api/CognitoApiFeature.js.map +1 -1
  31. package/api/domain/errors.d.ts +68 -0
  32. package/api/domain/errors.js +73 -1
  33. package/api/domain/errors.js.map +1 -1
  34. package/api/features/CheckEmail/CheckEmailUseCase.d.ts +16 -0
  35. package/api/features/CheckEmail/CheckEmailUseCase.js +47 -0
  36. package/api/features/CheckEmail/CheckEmailUseCase.js.map +1 -0
  37. package/api/features/CheckEmail/abstractions.d.ts +29 -0
  38. package/api/features/CheckEmail/abstractions.js +5 -0
  39. package/api/features/CheckEmail/abstractions.js.map +1 -0
  40. package/api/features/CheckEmail/feature.d.ts +4 -0
  41. package/api/features/CheckEmail/feature.js +11 -0
  42. package/api/features/CheckEmail/feature.js.map +1 -0
  43. package/api/features/CheckEmail/index.d.ts +2 -0
  44. package/api/features/CheckEmail/index.js +2 -0
  45. package/api/features/CognitoIdp/CognitoIdentityProvider.d.ts +2 -0
  46. package/api/features/CognitoIdp/CognitoIdentityProvider.js +20 -0
  47. package/api/features/CognitoIdp/CognitoIdentityProvider.js.map +1 -1
  48. package/api/features/CognitoIdp/abstractions.d.ts +6 -0
  49. package/api/features/CognitoIdp/abstractions.js.map +1 -1
  50. package/api/features/CognitoService/CognitoService.d.ts +2 -1
  51. package/api/features/CognitoService/CognitoService.js +20 -5
  52. package/api/features/CognitoService/CognitoService.js.map +1 -1
  53. package/api/features/CognitoService/abstractions.d.ts +13 -2
  54. package/api/features/CognitoService/abstractions.js.map +1 -1
  55. package/api/features/CognitoService/adminDeleteSoftwareToken.d.ts +16 -0
  56. package/api/features/CognitoService/adminDeleteSoftwareToken.js +69 -0
  57. package/api/features/CognitoService/adminDeleteSoftwareToken.js.map +1 -0
  58. package/api/features/CognitoService/adminDeleteSoftwareToken.test.d.ts +1 -0
  59. package/api/features/CognitoService/adminDeleteSoftwareToken.test.js +91 -0
  60. package/api/features/CognitoService/adminDeleteSoftwareToken.test.js.map +1 -0
  61. package/api/features/CreateUser/CreateUserUseCase.d.ts +1 -2
  62. package/api/features/CreateUser/CreateUserUseCase.js +3 -3
  63. package/api/features/CreateUser/CreateUserUseCase.js.map +1 -1
  64. package/api/features/CreateUser/abstractions.d.ts +3 -1
  65. package/api/features/CreateUser/abstractions.js.map +1 -1
  66. package/api/features/DeleteUser/DeleteUserUseCase.d.ts +3 -1
  67. package/api/features/DeleteUser/DeleteUserUseCase.js +11 -2
  68. package/api/features/DeleteUser/DeleteUserUseCase.js.map +1 -1
  69. package/api/features/DeleteUser/abstractions.d.ts +2 -0
  70. package/api/features/DeleteUser/abstractions.js.map +1 -1
  71. package/api/features/LinkUser/LinkUserUseCase.d.ts +22 -0
  72. package/api/features/LinkUser/LinkUserUseCase.js +83 -0
  73. package/api/features/LinkUser/LinkUserUseCase.js.map +1 -0
  74. package/api/features/LinkUser/abstractions.d.ts +36 -0
  75. package/api/features/LinkUser/abstractions.js +5 -0
  76. package/api/features/LinkUser/abstractions.js.map +1 -0
  77. package/api/features/LinkUser/feature.d.ts +4 -0
  78. package/api/features/LinkUser/feature.js +11 -0
  79. package/api/features/LinkUser/feature.js.map +1 -0
  80. package/api/features/LinkUser/index.d.ts +2 -0
  81. package/api/features/LinkUser/index.js +2 -0
  82. package/api/features/ResetUserMfa/ResetUserMfaUseCase.d.ts +18 -0
  83. package/api/features/ResetUserMfa/ResetUserMfaUseCase.js +59 -0
  84. package/api/features/ResetUserMfa/ResetUserMfaUseCase.js.map +1 -0
  85. package/api/features/ResetUserMfa/abstractions.d.ts +24 -0
  86. package/api/features/ResetUserMfa/abstractions.js +5 -0
  87. package/api/features/ResetUserMfa/abstractions.js.map +1 -0
  88. package/api/features/ResetUserMfa/feature.d.ts +4 -0
  89. package/api/features/ResetUserMfa/feature.js +11 -0
  90. package/api/features/ResetUserMfa/feature.js.map +1 -0
  91. package/api/features/ResetUserMfa/index.d.ts +2 -0
  92. package/api/features/ResetUserMfa/index.js +2 -0
  93. package/api/features/UpdateUser/UpdateUserUseCase.d.ts +24 -1
  94. package/api/features/UpdateUser/UpdateUserUseCase.js +97 -4
  95. package/api/features/UpdateUser/UpdateUserUseCase.js.map +1 -1
  96. package/api/features/UpdateUser/abstractions.d.ts +7 -1
  97. package/api/features/UpdateUser/abstractions.js.map +1 -1
  98. package/api/features/UserInstaller/UserInstaller.d.ts +3 -1
  99. package/api/features/UserInstaller/UserInstaller.js +18 -3
  100. package/api/features/UserInstaller/UserInstaller.js.map +1 -1
  101. package/api/graphql/user.gql.js +87 -0
  102. package/api/graphql/user.gql.js.map +1 -1
  103. package/package.json +24 -19
package/admin/Cognito.js CHANGED
@@ -1,7 +1,13 @@
1
1
  import react, { Fragment, memo } from "react";
2
2
  import { AdminUsers } from "@webiny/app-admin";
3
3
  import { CognitoLogin } from "./CognitoLogin.js";
4
- const CognitoIdP = (props)=>/*#__PURE__*/ react.createElement(Fragment, null, /*#__PURE__*/ react.createElement(CognitoLogin, props.login), /*#__PURE__*/ react.createElement(AdminUsers, null));
4
+ const ADMIN_USERS_CAPABILITIES = {
5
+ linkAccounts: true,
6
+ resetMfa: true
7
+ };
8
+ const CognitoIdP = (props)=>/*#__PURE__*/ react.createElement(Fragment, null, /*#__PURE__*/ react.createElement(CognitoLogin, props.login), /*#__PURE__*/ react.createElement(AdminUsers, {
9
+ capabilities: ADMIN_USERS_CAPABILITIES
10
+ }));
5
11
  const CognitoAdmin = /*#__PURE__*/ memo(CognitoIdP);
6
12
  export { CognitoAdmin };
7
13
 
@@ -1 +1 @@
1
- {"version":3,"file":"admin/Cognito.js","sources":["../../src/admin/Cognito.tsx"],"sourcesContent":["import React from \"react\";\nimport { Fragment } from \"react\";\nimport { memo } from \"react\";\nimport { AdminUsers } from \"@webiny/app-admin\";\nimport { CognitoLogin } from \"./CognitoLogin.js\";\nimport type { CognitoLoginProps } from \"./CognitoLogin.js\";\n\nexport interface CognitoAdminProps {\n login: CognitoLoginProps;\n}\n\nconst CognitoIdP = (props: CognitoAdminProps) => {\n return (\n <Fragment>\n <CognitoLogin {...props.login} />\n <AdminUsers />\n </Fragment>\n );\n};\n\nexport const CognitoAdmin = memo(CognitoIdP);\n"],"names":["CognitoIdP","props","Fragment","CognitoLogin","AdminUsers","CognitoAdmin","memo"],"mappings":";;;AAWA,MAAMA,aAAa,CAACC,QACT,WAAP,GACI,oBAACC,UAAQA,MAAAA,WAAAA,GACL,oBAACC,cAAiBF,MAAM,KAAK,iBAC7B,oBAACG,YAAUA;AAKhB,MAAMC,eAAe,WAAHA,GAAGC,KAAKN"}
1
+ {"version":3,"file":"admin/Cognito.js","sources":["../../src/admin/Cognito.tsx"],"sourcesContent":["import React from \"react\";\nimport { Fragment } from \"react\";\nimport { memo } from \"react\";\nimport { AdminUsers } from \"@webiny/app-admin\";\nimport { CognitoLogin } from \"./CognitoLogin.js\";\nimport type { CognitoLoginProps } from \"./CognitoLogin.js\";\n\n/**\n * A Cognito account is shared by all of the person's tenants, and Cognito can drop a user's TOTP\n * token, so both are on.\n */\nconst ADMIN_USERS_CAPABILITIES = { linkAccounts: true, resetMfa: true };\n\nexport interface CognitoAdminProps {\n login: CognitoLoginProps;\n}\n\nconst CognitoIdP = (props: CognitoAdminProps) => {\n return (\n <Fragment>\n <CognitoLogin {...props.login} />\n <AdminUsers capabilities={ADMIN_USERS_CAPABILITIES} />\n </Fragment>\n );\n};\n\nexport const CognitoAdmin = memo(CognitoIdP);\n"],"names":["ADMIN_USERS_CAPABILITIES","CognitoIdP","props","Fragment","CognitoLogin","AdminUsers","CognitoAdmin","memo"],"mappings":";;;AAWA,MAAMA,2BAA2B;IAAE,cAAc;IAAM,UAAU;AAAK;AAMtE,MAAMC,aAAa,CAACC,QACT,WAAP,GACI,oBAACC,UAAQA,MAAAA,WAAAA,GACL,oBAACC,cAAiBF,MAAM,KAAK,iBAC7B,oBAACG,YAAUA;QAAC,cAAcL;;AAK/B,MAAMM,eAAe,WAAfA,GAAeC,KAAKN"}
@@ -10,6 +10,8 @@ import { SetNewPassword } from "./components/SetNewPassword.js";
10
10
  import { PasswordResetCodeSent } from "./components/PasswordResetCodeSent.js";
11
11
  import { ConfirmTotpCode } from "./components/ConfirmTotpCode.js";
12
12
  import { SetupTotp } from "./components/SetupTotp.js";
13
+ import { SelectTenant } from "./components/SelectTenant.js";
14
+ import { NoTenantAccess } from "./components/NoTenantAccess.js";
13
15
  const CognitoLoginScreen = observer((props)=>{
14
16
  const { presenter } = useFeature(CognitoFeature);
15
17
  useEffect(()=>{
@@ -49,7 +51,13 @@ const CognitoLoginScreen = observer((props)=>{
49
51
  }), "setupTotp" === vm.authState && /*#__PURE__*/ react.createElement(SetupTotp, {
50
52
  vm: vm.setupTotp,
51
53
  onSubmit: (code)=>presenter.verifyTotpSetup(code)
52
- }), ("signIn" === vm.authState || "signedOut" === vm.authState) && /*#__PURE__*/ react.createElement(SignIn, {
54
+ }), "selectTenant" === vm.authState ? /*#__PURE__*/ react.createElement(SelectTenant, {
55
+ vm: vm.selectTenant,
56
+ onSelect: (tenantId)=>presenter.selectTenant(tenantId),
57
+ onSignOut: ()=>presenter.signOut()
58
+ }) : null, "noTenantAccess" === vm.authState ? /*#__PURE__*/ react.createElement(NoTenantAccess, {
59
+ onSignOut: ()=>presenter.signOut()
60
+ }) : null, ("signIn" === vm.authState || "signedOut" === vm.authState) && /*#__PURE__*/ react.createElement(SignIn, {
53
61
  vm: vm.signIn,
54
62
  onSubmit: (username, password)=>presenter.signIn(username, password),
55
63
  onForgotPassword: ()=>presenter.showRequestPasswordResetCode()
@@ -1 +1 @@
1
- {"version":3,"file":"admin/presentation/Cognito/CognitoLoginScreen.js","sources":["../../../../src/admin/presentation/Cognito/CognitoLoginScreen.tsx"],"sourcesContent":["import React, { useEffect } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { useFeature } from \"@webiny/app\";\nimport { OverlayLoader } from \"@webiny/admin-ui\";\nimport { CognitoFeature } from \"./feature.js\";\nimport { SignIn } from \"./components/SignIn.js\";\nimport { RequireNewPassword } from \"./components/RequireNewPassword.js\";\nimport { RequestPasswordResetCode } from \"./components/RequestPasswordResetCode.js\";\nimport { SetNewPassword } from \"./components/SetNewPassword.js\";\nimport { PasswordResetCodeSent } from \"~/admin/presentation/Cognito/components/PasswordResetCodeSent.js\";\nimport { ConfirmTotpCode } from \"./components/ConfirmTotpCode.js\";\nimport { SetupTotp } from \"./components/SetupTotp.js\";\n\nexport interface CognitoLoginScreenProps {\n region: string;\n userPoolId: string;\n clientId: string;\n children: React.ReactNode;\n}\n\nexport const CognitoLoginScreen = observer((props: CognitoLoginScreenProps) => {\n const { presenter } = useFeature(CognitoFeature);\n\n useEffect(() => {\n presenter.init({\n region: props.region,\n userPoolId: props.userPoolId,\n clientId: props.clientId\n });\n }, []);\n\n const vm = presenter.vm;\n\n if (vm.isAuthenticated) {\n return <>{props.children}</>;\n }\n\n return (\n <>\n {vm.isLoggingIn ? <OverlayLoader text={\"Signing in...\"} /> : null}\n {vm.checkingSession ? <OverlayLoader text={\"Checking session...\"} /> : null}\n\n {!vm.isLoggingIn && !vm.checkingSession ? (\n <>\n {vm.authState === \"requireNewPassword\" && (\n <RequireNewPassword\n vm={vm.requireNewPassword}\n onSubmit={(password, attributes) =>\n presenter.confirmNewPassword(password, attributes)\n }\n onCancel={() => presenter.showSignIn()}\n />\n )}\n\n {vm.authState === \"requestPasswordResetCode\" && (\n <RequestPasswordResetCode\n vm={vm.requestPasswordResetCode}\n onRequestCode={username => presenter.requestPasswordReset(username)}\n onCancel={() => presenter.showSignIn()}\n />\n )}\n\n {vm.authState === \"passwordResetCodeSent\" && (\n <PasswordResetCodeSent\n vm={vm.passwordResetCodeSent}\n onResendCode={() => presenter.resendPasswordResetCode()}\n onCodeAcquired={() => presenter.showSetNewPassword()}\n onCancel={() => presenter.showSignIn()}\n />\n )}\n\n {vm.authState === \"setNewPassword\" && (\n <SetNewPassword\n vm={vm.setNewPassword}\n onSetNewPassword={(code, password) =>\n presenter.confirmPasswordReset(code, password)\n }\n onCancel={() => presenter.showSignIn()}\n />\n )}\n\n {vm.authState === \"confirmTotpCode\" && (\n <ConfirmTotpCode\n vm={vm.confirmTotpCode}\n onSubmit={code => presenter.confirmTotpCode(code)}\n onCancel={() => presenter.showSignIn()}\n />\n )}\n\n {vm.authState === \"setupTotp\" && (\n <SetupTotp\n vm={vm.setupTotp}\n onSubmit={code => presenter.verifyTotpSetup(code)}\n />\n )}\n\n {(vm.authState === \"signIn\" || vm.authState === \"signedOut\") && (\n <SignIn\n vm={vm.signIn}\n onSubmit={(username, password) => presenter.signIn(username, password)}\n onForgotPassword={() => presenter.showRequestPasswordResetCode()}\n />\n )}\n </>\n ) : null}\n </>\n );\n});\n"],"names":["CognitoLoginScreen","observer","props","presenter","useFeature","CognitoFeature","useEffect","vm","OverlayLoader","RequireNewPassword","password","attributes","RequestPasswordResetCode","username","PasswordResetCodeSent","SetNewPassword","code","ConfirmTotpCode","SetupTotp","SignIn"],"mappings":";;;;;;;;;;;;AAoBO,MAAMA,qBAAqBC,SAAS,CAACC;IACxC,MAAM,EAAEC,SAAS,EAAE,GAAGC,WAAWC;IAEjCC,UAAU;QACNH,UAAU,IAAI,CAAC;YACX,QAAQD,MAAM,MAAM;YACpB,YAAYA,MAAM,UAAU;YAC5B,UAAUA,MAAM,QAAQ;QAC5B;IACJ,GAAG,EAAE;IAEL,MAAMK,KAAKJ,UAAU,EAAE;IAEvB,IAAII,GAAG,eAAe,EAClB,OAAO,WAAP,GAAO,0CAAGL,MAAM,QAAQ;IAG5B,OAAO,WAAP,GACI,0CACKK,GAAG,WAAW,GAAG,WAAH,GAAG,oBAACC,eAAaA;QAAC,MAAM;SAAsB,MAC5DD,GAAG,eAAe,GAAG,WAAH,GAAG,oBAACC,eAAaA;QAAC,MAAM;SAA4B,MAEtE,AAACD,GAAG,WAAW,IAAKA,GAAG,eAAe,GA8DnC,OA9DsC,WAAH,GACnC,0CACKA,AAAiB,yBAAjBA,GAAG,SAAS,IAA6B,WAAxB,GACd,oBAACE,oBAAkBA;QACf,IAAIF,GA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AAO1F"}
1
+ {"version":3,"file":"admin/presentation/Cognito/CognitoLoginScreen.js","sources":["../../../../src/admin/presentation/Cognito/CognitoLoginScreen.tsx"],"sourcesContent":["import React, { useEffect } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { useFeature } from \"@webiny/app\";\nimport { OverlayLoader } from \"@webiny/admin-ui\";\nimport { CognitoFeature } from \"./feature.js\";\nimport { SignIn } from \"./components/SignIn.js\";\nimport { RequireNewPassword } from \"./components/RequireNewPassword.js\";\nimport { RequestPasswordResetCode } from \"./components/RequestPasswordResetCode.js\";\nimport { SetNewPassword } from \"./components/SetNewPassword.js\";\nimport { PasswordResetCodeSent } from \"~/admin/presentation/Cognito/components/PasswordResetCodeSent.js\";\nimport { ConfirmTotpCode } from \"./components/ConfirmTotpCode.js\";\nimport { SetupTotp } from \"./components/SetupTotp.js\";\nimport { SelectTenant } from \"./components/SelectTenant.js\";\nimport { NoTenantAccess } from \"./components/NoTenantAccess.js\";\n\nexport interface CognitoLoginScreenProps {\n region: string;\n userPoolId: string;\n clientId: string;\n children: React.ReactNode;\n}\n\nexport const CognitoLoginScreen = observer((props: CognitoLoginScreenProps) => {\n const { presenter } = useFeature(CognitoFeature);\n\n useEffect(() => {\n presenter.init({\n region: props.region,\n userPoolId: props.userPoolId,\n clientId: props.clientId\n });\n }, []);\n\n const vm = presenter.vm;\n\n if (vm.isAuthenticated) {\n return <>{props.children}</>;\n }\n\n return (\n <>\n {vm.isLoggingIn ? <OverlayLoader text={\"Signing in...\"} /> : null}\n {vm.checkingSession ? <OverlayLoader text={\"Checking session...\"} /> : null}\n\n {!vm.isLoggingIn && !vm.checkingSession ? (\n <>\n {vm.authState === \"requireNewPassword\" && (\n <RequireNewPassword\n vm={vm.requireNewPassword}\n onSubmit={(password, attributes) =>\n presenter.confirmNewPassword(password, attributes)\n }\n onCancel={() => presenter.showSignIn()}\n />\n )}\n\n {vm.authState === \"requestPasswordResetCode\" && (\n <RequestPasswordResetCode\n vm={vm.requestPasswordResetCode}\n onRequestCode={username => presenter.requestPasswordReset(username)}\n onCancel={() => presenter.showSignIn()}\n />\n )}\n\n {vm.authState === \"passwordResetCodeSent\" && (\n <PasswordResetCodeSent\n vm={vm.passwordResetCodeSent}\n onResendCode={() => presenter.resendPasswordResetCode()}\n onCodeAcquired={() => presenter.showSetNewPassword()}\n onCancel={() => presenter.showSignIn()}\n />\n )}\n\n {vm.authState === \"setNewPassword\" && (\n <SetNewPassword\n vm={vm.setNewPassword}\n onSetNewPassword={(code, password) =>\n presenter.confirmPasswordReset(code, password)\n }\n onCancel={() => presenter.showSignIn()}\n />\n )}\n\n {vm.authState === \"confirmTotpCode\" && (\n <ConfirmTotpCode\n vm={vm.confirmTotpCode}\n onSubmit={code => presenter.confirmTotpCode(code)}\n onCancel={() => presenter.showSignIn()}\n />\n )}\n\n {vm.authState === \"setupTotp\" && (\n <SetupTotp\n vm={vm.setupTotp}\n onSubmit={code => presenter.verifyTotpSetup(code)}\n />\n )}\n\n {vm.authState === \"selectTenant\" ? (\n <SelectTenant\n vm={vm.selectTenant}\n onSelect={tenantId => presenter.selectTenant(tenantId)}\n onSignOut={() => presenter.signOut()}\n />\n ) : null}\n\n {vm.authState === \"noTenantAccess\" ? (\n <NoTenantAccess onSignOut={() => presenter.signOut()} />\n ) : null}\n\n {(vm.authState === \"signIn\" || vm.authState === \"signedOut\") && (\n <SignIn\n vm={vm.signIn}\n onSubmit={(username, password) => presenter.signIn(username, password)}\n onForgotPassword={() => presenter.showRequestPasswordResetCode()}\n />\n )}\n </>\n ) : null}\n </>\n );\n});\n"],"names":["CognitoLoginScreen","observer","props","presenter","useFeature","CognitoFeature","useEffect","vm","OverlayLoader","RequireNewPassword","password","attributes","RequestPasswordResetCode","username","PasswordResetCodeSent","SetNewPassword","code","ConfirmTotpCode","SetupTotp","SelectTenant","tenantId","NoTenantAccess","SignIn"],"mappings":";;;;;;;;;;;;;;AAsBO,MAAMA,qBAAqBC,SAAS,CAACC;IACxC,MAAM,EAA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oBAAoB,CAACa,MAAMN;QAEzC,UAAU,IAAMP,UAAU,UAAU;QAI3CI,AAAiB,sBAAjBA,GAAG,SAAS,IAA0B,WAArB,GACd,oBAACU,iBAAeA;QACZ,IAAIV,GAAG,eAAe;QACtB,UAAUS,CAAAA,OAAQb,UAAU,eAAe,CAACa;QAC5C,UAAU,IAAMb,UAAU,UAAU;QAI3CI,AAAiB,gBAAjBA,GAAG,SAAS,IAAoB,WAAf,GACd,oBAACW,WAASA;QACN,IAAIX,GAAG,SAAS;QAChB,UAAUS,CAAAA,OAAQb,UAAU,eAAe,CAACa;QAInDT,AAAiB,mBAAjBA,GAAG,SAAS,GAAsB,WAAjB,GACd,oBAACY,cAAYA;QACT,IAAIZ,GAAG,YAAY;QACnB,UAAUa,CAAAA,WAAYjB,UAAU,YAAY,CAACiB;QAC7C,WAAW,IAAMjB,UAAU,OAAO;SAEtC,MAEHI,AAAiB,qBAAjBA,GAAG,SAAS,GAAwB,WAAnB,GACd,oBAACc,gBAAcA;QAAC,WAAW,IAAMlB,UAAU,OAAO;SAClD,MAEFI,AAAAA,CAAAA,AAAiB,aAAjBA,GAAG,SAAS,IAAiBA,AAAiB,gBAAjBA,GAAG,SAAS,AAAe,mBACtD,oBAACe,QAAMA;QACH,IAAIf,GAAG,MAAM;QACb,UAAU,CAACM,UAAUH,WAAaP,UAAU,MAAM,CAACU,UAAUH;QAC7D,kBAAkB,IAAMP,UAAU,4BAA4B;;AAO1F"}
@@ -1,10 +1,13 @@
1
1
  import { CognitoPresenter as CognitoPresenterAbstraction, AuthState, AuthMessage, ICognitoInitParams } from "./abstractions.js";
2
2
  import { LogInUseCase } from "@webiny/app-admin/features/security/LogIn/index.js";
3
3
  import { IdentityContext } from "@webiny/app-admin/features/security/IdentityContext/index.js";
4
+ import { TenantContext } from "@webiny/app-admin/features/tenancy/abstractions.js";
5
+ import type { Tenant } from "@webiny/app-admin/features/tenancy/abstractions.js";
4
6
  import { CognitoSignInConfig } from "./CognitoSignInConfig.js";
5
7
  declare class CognitoPresenterImpl implements CognitoPresenterAbstraction.Interface {
6
8
  private identity;
7
9
  private logInUseCase;
10
+ private tenantContext;
8
11
  private signInConfig;
9
12
  private authState;
10
13
  private authData;
@@ -19,7 +22,8 @@ declare class CognitoPresenterImpl implements CognitoPresenterAbstraction.Interf
19
22
  private federatedProviders;
20
23
  private totpSharedSecret;
21
24
  private totpQrCodeUri;
22
- constructor(identity: IdentityContext.Interface, logInUseCase: LogInUseCase.Interface, signInConfig: CognitoSignInConfig.Interface | undefined);
25
+ private tenants;
26
+ constructor(identity: IdentityContext.Interface, logInUseCase: LogInUseCase.Interface, tenantContext: TenantContext.Interface, signInConfig: CognitoSignInConfig.Interface | undefined);
23
27
  get vm(): {
24
28
  authState: AuthState;
25
29
  checkingSession: boolean;
@@ -59,6 +63,9 @@ declare class CognitoPresenterImpl implements CognitoPresenterAbstraction.Interf
59
63
  qrCodeUri: string;
60
64
  message: AuthMessage | null;
61
65
  };
66
+ selectTenant: {
67
+ tenants: Tenant[];
68
+ };
62
69
  };
63
70
  init(params: ICognitoInitParams): Promise<void>;
64
71
  signIn(username: string, password: string): Promise<void>;
@@ -68,6 +75,8 @@ declare class CognitoPresenterImpl implements CognitoPresenterAbstraction.Interf
68
75
  confirmPasswordReset(code: string, password: string): Promise<void>;
69
76
  confirmTotpCode(code: string): Promise<void>;
70
77
  verifyTotpSetup(code: string): Promise<void>;
78
+ selectTenant(tenantId: string): void;
79
+ signOut(): Promise<void>;
71
80
  showSignIn(): void;
72
81
  showRequestPasswordResetCode(): void;
73
82
  showSetNewPassword(): void;
@@ -4,12 +4,14 @@ import { confirmResetPassword, confirmSignIn, fetchAuthSession, resetPassword, s
4
4
  import { CognitoPresenter } from "./abstractions.js";
5
5
  import { LogInUseCase } from "@webiny/app-admin/features/security/LogIn/index.js";
6
6
  import { IdentityContext } from "@webiny/app-admin/features/security/IdentityContext/index.js";
7
+ import { TenantContext } from "@webiny/app-admin/features/tenancy/abstractions.js";
7
8
  import { CognitoSignInConfig } from "./CognitoSignInConfig.js";
8
9
  const federatedDescription = "You will be taken to an external service to complete the sign-in process.";
9
10
  class CognitoPresenterImpl {
10
- constructor(identity, logInUseCase, signInConfig){
11
+ constructor(identity, logInUseCase, tenantContext, signInConfig){
11
12
  this.identity = identity;
12
13
  this.logInUseCase = logInUseCase;
14
+ this.tenantContext = tenantContext;
13
15
  this.signInConfig = signInConfig;
14
16
  this.authState = "signIn";
15
17
  this.authData = null;
@@ -24,6 +26,7 @@ class CognitoPresenterImpl {
24
26
  this.federatedProviders = [];
25
27
  this.totpSharedSecret = "";
26
28
  this.totpQrCodeUri = "";
29
+ this.tenants = [];
27
30
  makeAutoObservable(this);
28
31
  }
29
32
  get vm() {
@@ -66,6 +69,9 @@ class CognitoPresenterImpl {
66
69
  sharedSecret: this.totpSharedSecret,
67
70
  qrCodeUri: this.totpQrCodeUri,
68
71
  message: this.message
72
+ },
73
+ selectTenant: {
74
+ tenants: this.tenants
69
75
  }
70
76
  };
71
77
  }
@@ -304,6 +310,24 @@ class CognitoPresenterImpl {
304
310
  });
305
311
  }
306
312
  }
313
+ selectTenant(tenantId) {
314
+ runInAction(()=>{
315
+ this.isLoggingIn = true;
316
+ });
317
+ this.tenantContext.setTenant(tenantId);
318
+ }
319
+ async signOut() {
320
+ try {
321
+ await signOut();
322
+ } finally{
323
+ runInAction(()=>{
324
+ this.authState = "signIn";
325
+ this.authData = null;
326
+ this.message = null;
327
+ this.tenants = [];
328
+ });
329
+ }
330
+ }
307
331
  showSignIn() {
308
332
  this.authState = "signIn";
309
333
  this.authData = null;
@@ -321,8 +345,9 @@ class CognitoPresenterImpl {
321
345
  runInAction(()=>{
322
346
  this.isLoggingIn = true;
323
347
  });
348
+ let switchingTenant = false;
324
349
  try {
325
- await this.logInUseCase.execute({
350
+ const result = await this.logInUseCase.execute({
326
351
  idTokenProvider: async ()=>{
327
352
  const session = await fetchAuthSession();
328
353
  const idToken = session.tokens?.idToken;
@@ -337,16 +362,36 @@ class CognitoPresenterImpl {
337
362
  });
338
363
  }
339
364
  });
365
+ switchingTenant = "switchingTenant" === result.type;
340
366
  runInAction(()=>{
341
- this.authState = "signedIn";
367
+ switch(result.type){
368
+ case "loggedIn":
369
+ this.authState = "signedIn";
370
+ break;
371
+ case "selectTenant":
372
+ this.tenants = result.tenants;
373
+ this.authState = "selectTenant";
374
+ break;
375
+ case "noTenantAccess":
376
+ this.authState = "noTenantAccess";
377
+ break;
378
+ }
342
379
  });
343
380
  } catch (error) {
344
381
  console.error("Error during sign in:", error);
382
+ try {
383
+ await signOut();
384
+ } catch {}
345
385
  runInAction(()=>{
346
386
  this.authState = "signIn";
387
+ this.message = {
388
+ title: "Login Failed",
389
+ text: error.message,
390
+ type: "danger"
391
+ };
347
392
  });
348
393
  } finally{
349
- runInAction(()=>{
394
+ if (!switchingTenant) runInAction(()=>{
350
395
  this.isLoggingIn = false;
351
396
  });
352
397
  }
@@ -373,6 +418,7 @@ const CognitoPresenter_CognitoPresenter = CognitoPresenter.createImplementation(
373
418
  dependencies: [
374
419
  IdentityContext,
375
420
  LogInUseCase,
421
+ TenantContext,
376
422
  [
377
423
  CognitoSignInConfig,
378
424
  {
@@ -1 +1 @@
1
- {"version":3,"file":"admin/presentation/Cognito/CognitoPresenter.js","sources":["../../../../src/admin/presentation/Cognito/CognitoPresenter.ts"],"sourcesContent":["import { makeAutoObservable, runInAction } from \"mobx\";\nimport { Amplify } from \"aws-amplify\";\nimport {\n signIn,\n signOut,\n confirmSignIn,\n resetPassword,\n confirmResetPassword,\n fetchAuthSession\n} from \"aws-amplify/auth\";\nimport {\n CognitoPresenter as CognitoPresenterAbstraction,\n AuthState,\n AuthData,\n AuthMessage,\n ICognitoInitParams\n} from \"./abstractions.js\";\nimport { LogInUseCase } from \"@webiny/app-admin/features/security/LogIn/index.js\";\nimport { IdentityContext } from \"@webiny/app-admin/features/security/IdentityContext/index.js\";\nimport { CognitoSignInConfig } from \"./CognitoSignInConfig.js\";\n\nconst federatedDescription =\n \"You will be taken to an external service to complete the sign-in process.\";\n\nclass CognitoPresenterImpl implements CognitoPresenterAbstraction.Interface {\n private authState: AuthState = \"signIn\";\n private authData: AuthData | null = null;\n private message: AuthMessage | null = null;\n private checkingSession = false;\n private isLoggingIn = false;\n private formLoading = false;\n private initialized = false;\n\n private signInTitle = \"Sign in\";\n private signInDescription: string | undefined = undefined;\n private allowCredentialsLogin = true;\n private federatedProviders: CognitoSignInConfig.FederatedProvider[] = [];\n\n private totpSharedSecret = \"\";\n private totpQrCodeUri = \"\";\n\n constructor(\n private identity: IdentityContext.Interface,\n private logInUseCase: LogInUseCase.Interface,\n private signInConfig: CognitoSignInConfig.Interface | undefined\n ) {\n makeAutoObservable(this);\n }\n\n get vm() {\n const identity = this.identity.getIdentity();\n\n return {\n authState: this.authState,\n checkingSession: this.checkingSession,\n isLoggingIn: this.isLoggingIn,\n isAuthenticated: identity.isAuthenticated,\n\n // View-specific VMs\n signIn: {\n isLoading: this.formLoading,\n message: this.message,\n title: this.signInTitle,\n description: this.signInDescription,\n allowCredentialsLogin: this.allowCredentialsLogin,\n federatedProviders: this.federatedProviders\n },\n requestPasswordResetCode: {\n isLoading: this.formLoading,\n message: this.message\n },\n passwordResetCodeSent: {\n isLoading: this.formLoading,\n message: this.message\n },\n setNewPassword: {\n isLoading: this.formLoading,\n message: this.message\n },\n requireNewPassword: {\n isLoading: this.formLoading,\n requiredAttributes: (this.authData && this.authData.requiredAttributes) || []\n },\n confirmTotpCode: {\n isLoading: this.formLoading,\n message: this.message\n },\n setupTotp: {\n isLoading: this.formLoading,\n sharedSecret: this.totpSharedSecret,\n qrCodeUri: this.totpQrCodeUri,\n message: this.message\n }\n };\n }\n\n async init(params: ICognitoInitParams): Promise<void> {\n if (this.initialized) {\n return;\n }\n\n let oauthConfig:\n | { Cognito: { userPoolId: string; userPoolClientId: string; loginWith: any } }\n | undefined;\n\n if (this.signInConfig) {\n const config = await this.signInConfig.getConfig();\n\n runInAction(() => {\n this.signInTitle = config.title ?? \"Sign in\";\n this.signInDescription = config.description;\n\n if (!config.description && !config.allowCredentialsLogin) {\n this.signInDescription = federatedDescription;\n }\n\n this.allowCredentialsLogin = config.allowCredentialsLogin;\n this.federatedProviders = config.providers;\n });\n\n const domain = process.env.REACT_APP_USER_POOL_DOMAIN;\n if (domain) {\n oauthConfig = {\n Cognito: {\n userPoolId: params.userPoolId,\n userPoolClientId: params.clientId,\n loginWith: {\n oauth: {\n domain,\n redirectSignIn: config.oauth.redirectSignIn,\n redirectSignOut: config.oauth.redirectSignOut,\n scopes: config.oauth.scopes,\n responseType: config.oauth.responseType\n }\n }\n }\n };\n }\n }\n\n Amplify.configure({\n Auth: oauthConfig ?? {\n Cognito: {\n userPoolId: params.userPoolId,\n userPoolClientId: params.clientId\n }\n }\n });\n this.initialized = true;\n\n await this.checkUrl();\n }\n\n // Public API\n async signIn(username: string, password: string): Promise<void> {\n runInAction(() => {\n this.formLoading = true;\n this.message = null;\n });\n\n const usernameOrPassword = [\"UserNotFoundException\", \"NotAuthorizedException\"];\n\n try {\n const result = await signIn({ username, password });\n const { nextStep } = result;\n\n if (nextStep.signInStep === \"CONFIRM_SIGN_IN_WITH_NEW_PASSWORD_REQUIRED\") {\n runInAction(() => {\n this.authState = \"requireNewPassword\";\n this.authData = {\n requiredAttributes: nextStep.missingAttributes || []\n };\n this.formLoading = false;\n });\n } else if (nextStep.signInStep === \"CONFIRM_SIGN_IN_WITH_TOTP_CODE\") {\n runInAction(() => {\n this.authState = \"confirmTotpCode\";\n this.formLoading = false;\n });\n } else if (nextStep.signInStep === \"CONTINUE_SIGN_IN_WITH_TOTP_SETUP\") {\n const totpSetup = nextStep.totpSetupDetails;\n const uri = totpSetup.getSetupUri(\"Webiny\").toString();\n runInAction(() => {\n this.totpSharedSecret = totpSetup.sharedSecret;\n this.totpQrCodeUri = uri;\n this.authState = \"setupTotp\";\n this.formLoading = false;\n });\n } else {\n await this.handleSignedIn();\n runInAction(() => {\n this.formLoading = false;\n });\n }\n } catch (error) {\n let message = error.message;\n\n if (usernameOrPassword.includes(error.name)) {\n message = \"Incorrect username or password.\";\n }\n runInAction(() => {\n this.message = {\n title: \"Login Failed\",\n text: message,\n type: \"danger\"\n };\n this.formLoading = false;\n });\n }\n }\n\n async confirmNewPassword(password: string, requiredAttributes: any): Promise<void> {\n runInAction(() => {\n this.formLoading = true;\n this.message = null;\n });\n\n try {\n await confirmSignIn({\n challengeResponse: password,\n options: { userAttributes: requiredAttributes }\n });\n await this.handleSignedIn();\n } catch (error) {\n runInAction(() => {\n this.message = {\n title: \"Error\",\n text: error.message,\n type: \"danger\"\n };\n });\n } finally {\n runInAction(() => {\n this.formLoading = false;\n });\n }\n }\n\n async requestPasswordReset(username: string): Promise<void> {\n runInAction(() => {\n this.formLoading = true;\n this.message = null;\n });\n\n try {\n await resetPassword({ username });\n } catch {\n // We ignore errors and pretend that everything went fine.\n // Showing an error would give a potential attacker information about which usernames exist (or not).\n // This way it's more difficult to exploit the process.\n } finally {\n runInAction(() => {\n this.authState = \"passwordResetCodeSent\";\n this.authData = { username };\n this.formLoading = false;\n });\n }\n }\n\n async resendPasswordResetCode(): Promise<void> {\n const username = this.authData?.username;\n if (this.authState !== \"passwordResetCodeSent\" || !username) {\n return;\n }\n\n await this.requestPasswordReset(username!);\n runInAction(() => {\n this.message = {\n title: \"Code Resent\",\n text: \"Password reset code has been resent to your email address. Please check your inbox!\",\n type: \"success\"\n };\n });\n }\n\n async confirmPasswordReset(code: string, password: string): Promise<void> {\n const username = this.authData?.username;\n if (!username) {\n return;\n }\n\n runInAction(() => {\n this.formLoading = true;\n this.message = null;\n });\n\n try {\n await confirmResetPassword({\n username,\n confirmationCode: code,\n newPassword: password\n });\n runInAction(() => {\n this.authState = \"signIn\";\n this.message = {\n title: \"Password Reset\",\n text: \"You can now sign in with your new password\",\n type: \"success\"\n };\n });\n } catch (error) {\n runInAction(() => {\n this.message = {\n title: \"Error\",\n text: error.message,\n type: \"danger\"\n };\n });\n } finally {\n runInAction(() => {\n this.formLoading = false;\n });\n }\n }\n\n async confirmTotpCode(code: string): Promise<void> {\n runInAction(() => {\n this.formLoading = true;\n this.message = null;\n });\n\n try {\n await confirmSignIn({ challengeResponse: code });\n await this.handleSignedIn();\n } catch (error) {\n runInAction(() => {\n this.message = {\n title: \"Verification Failed\",\n text: error.message,\n type: \"danger\"\n };\n });\n } finally {\n runInAction(() => {\n this.formLoading = false;\n });\n }\n }\n\n async verifyTotpSetup(code: string): Promise<void> {\n runInAction(() => {\n this.formLoading = true;\n this.message = null;\n });\n\n try {\n await confirmSignIn({ challengeResponse: code });\n await this.handleSignedIn();\n } catch (error) {\n runInAction(() => {\n this.message = {\n title: \"Setup Failed\",\n text: error.message,\n type: \"danger\"\n };\n });\n } finally {\n runInAction(() => {\n this.formLoading = false;\n });\n }\n }\n\n showSignIn(): void {\n this.authState = \"signIn\";\n this.authData = null;\n this.message = null;\n }\n\n showRequestPasswordResetCode(): void {\n this.authState = \"requestPasswordResetCode\";\n this.message = null;\n }\n\n showSetNewPassword(): void {\n this.authState = \"setNewPassword\";\n this.message = null;\n }\n\n // Private/internal methods\n private async handleSignedIn(): Promise<void> {\n runInAction(() => {\n this.isLoggingIn = true;\n });\n\n try {\n await this.logInUseCase.execute({\n idTokenProvider: async () => {\n const session = await fetchAuthSession();\n const idToken = session.tokens?.idToken;\n if (!idToken) {\n throw new Error(\"No ID token available.\");\n }\n return idToken.toString();\n },\n logoutCallback: () => {\n signOut();\n runInAction(() => {\n this.authState = \"signIn\";\n this.authData = null;\n });\n }\n });\n\n runInAction(() => {\n this.authState = \"signedIn\";\n });\n } catch (error) {\n console.error(\"Error during sign in:\", error);\n runInAction(() => {\n this.authState = \"signIn\";\n });\n } finally {\n runInAction(() => {\n this.isLoggingIn = false;\n });\n }\n }\n\n private async checkUrl(): Promise<void> {\n return this.checkSession();\n }\n\n private async checkSession(): Promise<void> {\n runInAction(() => {\n this.checkingSession = true;\n });\n\n try {\n const session = await fetchAuthSession();\n if (session.tokens) {\n // We don't need to `await`, we simply start a separate \"branch\" of execution.\n this.handleSignedIn();\n }\n } catch {\n // Not authenticated, stay on signIn\n } finally {\n runInAction(() => {\n this.checkingSession = false;\n });\n }\n }\n}\n\nexport const CognitoPresenter = CognitoPresenterAbstraction.createImplementation({\n implementation: CognitoPresenterImpl,\n dependencies: [IdentityContext, LogInUseCase, [CognitoSignInConfig, { optional: true }]]\n});\n"],"names":["federatedDescription","CognitoPresenterImpl","identity","logInUseCase","signInConfig","undefined","makeAutoObservable","params","oauthConfig","config","runInAction","domain","process","Amplify","username","password","usernameOrPassword","result","signIn","nextStep","totpSetup","uri","error","message","requiredAttributes","confirmSignIn","resetPassword","code","confirmResetPassword","session","fetchAuthSession","idToken","Error","signOut","console","CognitoPresenter","CognitoPresenterAbstraction","IdentityContext","LogInUseCase","CognitoSignInConfig"],"mappings":";;;;;;;AAqBA,MAAMA,uBACF;AAEJ,MAAMC;IAiBF,YACYC,QAAmC,EACnCC,YAAoC,EACpCC,YAAuD,CACjE;aAHUF,QAAQ,GAARA;aACAC,YAAY,GAAZA;aACAC,YAAY,GAAZA;aAnBJ,SAAS,GAAc;aACvB,QAAQ,GAAoB;aAC5B,OAAO,GAAuB;aAC9B,eAAe,GAAG;aAClB,WAAW,GAAG;aACd,WAAW,GAAG;aACd,WAAW,GAAG;aAEd,WAAW,GAAG;aACd,iBAAiB,GAAuBC;aACxC,qBAAqB,GAAG;aACxB,kBAAkB,GAA4C,EAAE;aAEhE,gBAAgB,GAAG;aACnB,aAAa,GAAG;QAOpBC,mBAAmB,IAAI;IAC3B;IAEA,IAAI,KAAK;QACL,MAAMJ,WAAW,IAAI,CAAC,QAAQ,CAAC,WAAW;QAE1C,OAAO;YACH,WAAW,IAAI,CAAC,SAAS;YACzB,iBAAiB,IAAI,CAAC,eAAe;YACrC,aAAa,IAAI,CAAC,WAAW;YAC7B,iBAAiBA,SAAS,eAAe;YAGzC,QAAQ;gBACJ,WAAW,IAAI,CAAC,WAAW;gBAC3B,S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AgB;oBACZE;oBACAvB,YAAY;wBACR,IAAI,CAAC,SAAS,GAAG;wBACjB,IAAI,CAAC,QAAQ,GAAG;oBACpB;gBACJ;YACJ;YAEAA,YAAY;gBACR,IAAI,CAAC,SAAS,GAAG;YACrB;QACJ,EAAE,OAAOY,OAAO;YACZY,QAAQ,KAAK,CAAC,yBAAyBZ;YACvCZ,YAAY;gBACR,IAAI,CAAC,SAAS,GAAG;YACrB;QACJ,SAAU;YACNA,YAAY;gBACR,IAAI,CAAC,WAAW,GAAG;YACvB;QACJ;IACJ;IAEA,MAAc,WAA0B;QACpC,OAAO,IAAI,CAAC,YAAY;IAC5B;IAEA,MAAc,eAA8B;QACxCA,YAAY;YACR,IAAI,CAAC,eAAe,GAAG;QAC3B;QAEA,IAAI;YACA,MAAMmB,UAAU,MAAMC;YACtB,IAAID,QAAQ,MAAM,EAEd,IAAI,CAAC,cAAc;QAE3B,EAAE,OAAM,CAER,SAAU;YACNnB,YAAY;gBACR,IAAI,CAAC,eAAe,GAAG;YAC3B;QACJ;IACJ;AACJ;AAEO,MAAMyB,oCAAmBC,iBAAAA,oBAAgD,CAAC;IAC7E,gBAAgBnC;IAChB,cAAc;QAACoC;QAAiBC;QAAc;YAACC;YAAqB;gBAAE,UAAU;YAAK;SAAE;KAAC;AAC5F"}
1
+ {"version":3,"file":"admin/presentation/Cognito/CognitoPresenter.js","sources":["../../../../src/admin/presentation/Cognito/CognitoPresenter.ts"],"sourcesContent":["import { makeAutoObservable, runInAction } from \"mobx\";\nimport { Amplify } from \"aws-amplify\";\nimport {\n signIn,\n signOut,\n confirmSignIn,\n resetPassword,\n confirmResetPassword,\n fetchAuthSession\n} from \"aws-amplify/auth\";\nimport {\n CognitoPresenter as CognitoPresenterAbstraction,\n AuthState,\n AuthData,\n AuthMessage,\n ICognitoInitParams\n} from \"./abstractions.js\";\nimport { LogInUseCase } from \"@webiny/app-admin/features/security/LogIn/index.js\";\nimport { IdentityContext } from \"@webiny/app-admin/features/security/IdentityContext/index.js\";\nimport { TenantContext } from \"@webiny/app-admin/features/tenancy/abstractions.js\";\nimport type { Tenant } from \"@webiny/app-admin/features/tenancy/abstractions.js\";\nimport { CognitoSignInConfig } from \"./CognitoSignInConfig.js\";\n\nconst federatedDescription =\n \"You will be taken to an external service to complete the sign-in process.\";\n\nclass CognitoPresenterImpl implements CognitoPresenterAbstraction.Interface {\n private authState: AuthState = \"signIn\";\n private authData: AuthData | null = null;\n private message: AuthMessage | null = null;\n private checkingSession = false;\n private isLoggingIn = false;\n private formLoading = false;\n private initialized = false;\n\n private signInTitle = \"Sign in\";\n private signInDescription: string | undefined = undefined;\n private allowCredentialsLogin = true;\n private federatedProviders: CognitoSignInConfig.FederatedProvider[] = [];\n\n private totpSharedSecret = \"\";\n private totpQrCodeUri = \"\";\n\n private tenants: Tenant[] = [];\n\n constructor(\n private identity: IdentityContext.Interface,\n private logInUseCase: LogInUseCase.Interface,\n private tenantContext: TenantContext.Interface,\n private signInConfig: CognitoSignInConfig.Interface | undefined\n ) {\n makeAutoObservable(this);\n }\n\n get vm() {\n const identity = this.identity.getIdentity();\n\n return {\n authState: this.authState,\n checkingSession: this.checkingSession,\n isLoggingIn: this.isLoggingIn,\n isAuthenticated: identity.isAuthenticated,\n\n // View-specific VMs\n signIn: {\n isLoading: this.formLoading,\n message: this.message,\n title: this.signInTitle,\n description: this.signInDescription,\n allowCredentialsLogin: this.allowCredentialsLogin,\n federatedProviders: this.federatedProviders\n },\n requestPasswordResetCode: {\n isLoading: this.formLoading,\n message: this.message\n },\n passwordResetCodeSent: {\n isLoading: this.formLoading,\n message: this.message\n },\n setNewPassword: {\n isLoading: this.formLoading,\n message: this.message\n },\n requireNewPassword: {\n isLoading: this.formLoading,\n requiredAttributes: (this.authData && this.authData.requiredAttributes) || []\n },\n confirmTotpCode: {\n isLoading: this.formLoading,\n message: this.message\n },\n setupTotp: {\n isLoading: this.formLoading,\n sharedSecret: this.totpSharedSecret,\n qrCodeUri: this.totpQrCodeUri,\n message: this.message\n },\n selectTenant: {\n tenants: this.tenants\n }\n };\n }\n\n async init(params: ICognitoInitParams): Promise<void> {\n if (this.initialized) {\n return;\n }\n\n let oauthConfig:\n | { Cognito: { userPoolId: string; userPoolClientId: string; loginWith: any } }\n | undefined;\n\n if (this.signInConfig) {\n const config = await this.signInConfig.getConfig();\n\n runInAction(() => {\n this.signInTitle = config.title ?? \"Sign in\";\n this.signInDescription = config.description;\n\n if (!config.description && !config.allowCredentialsLogin) {\n this.signInDescription = federatedDescription;\n }\n\n this.allowCredentialsLogin = config.allowCredentialsLogin;\n this.federatedProviders = config.providers;\n });\n\n const domain = process.env.REACT_APP_USER_POOL_DOMAIN;\n if (domain) {\n oauthConfig = {\n Cognito: {\n userPoolId: params.userPoolId,\n userPoolClientId: params.clientId,\n loginWith: {\n oauth: {\n domain,\n redirectSignIn: config.oauth.redirectSignIn,\n redirectSignOut: config.oauth.redirectSignOut,\n scopes: config.oauth.scopes,\n responseType: config.oauth.responseType\n }\n }\n }\n };\n }\n }\n\n Amplify.configure({\n Auth: oauthConfig ?? {\n Cognito: {\n userPoolId: params.userPoolId,\n userPoolClientId: params.clientId\n }\n }\n });\n this.initialized = true;\n\n await this.checkUrl();\n }\n\n // Public API\n async signIn(username: string, password: string): Promise<void> {\n runInAction(() => {\n this.formLoading = true;\n this.message = null;\n });\n\n const usernameOrPassword = [\"UserNotFoundException\", \"NotAuthorizedException\"];\n\n try {\n const result = await signIn({ username, password });\n const { nextStep } = result;\n\n if (nextStep.signInStep === \"CONFIRM_SIGN_IN_WITH_NEW_PASSWORD_REQUIRED\") {\n runInAction(() => {\n this.authState = \"requireNewPassword\";\n this.authData = {\n requiredAttributes: nextStep.missingAttributes || []\n };\n this.formLoading = false;\n });\n } else if (nextStep.signInStep === \"CONFIRM_SIGN_IN_WITH_TOTP_CODE\") {\n runInAction(() => {\n this.authState = \"confirmTotpCode\";\n this.formLoading = false;\n });\n } else if (nextStep.signInStep === \"CONTINUE_SIGN_IN_WITH_TOTP_SETUP\") {\n const totpSetup = nextStep.totpSetupDetails;\n const uri = totpSetup.getSetupUri(\"Webiny\").toString();\n runInAction(() => {\n this.totpSharedSecret = totpSetup.sharedSecret;\n this.totpQrCodeUri = uri;\n this.authState = \"setupTotp\";\n this.formLoading = false;\n });\n } else {\n await this.handleSignedIn();\n runInAction(() => {\n this.formLoading = false;\n });\n }\n } catch (error) {\n let message = error.message;\n\n if (usernameOrPassword.includes(error.name)) {\n message = \"Incorrect username or password.\";\n }\n runInAction(() => {\n this.message = {\n title: \"Login Failed\",\n text: message,\n type: \"danger\"\n };\n this.formLoading = false;\n });\n }\n }\n\n async confirmNewPassword(password: string, requiredAttributes: any): Promise<void> {\n runInAction(() => {\n this.formLoading = true;\n this.message = null;\n });\n\n try {\n await confirmSignIn({\n challengeResponse: password,\n options: { userAttributes: requiredAttributes }\n });\n await this.handleSignedIn();\n } catch (error) {\n runInAction(() => {\n this.message = {\n title: \"Error\",\n text: error.message,\n type: \"danger\"\n };\n });\n } finally {\n runInAction(() => {\n this.formLoading = false;\n });\n }\n }\n\n async requestPasswordReset(username: string): Promise<void> {\n runInAction(() => {\n this.formLoading = true;\n this.message = null;\n });\n\n try {\n await resetPassword({ username });\n } catch {\n // We ignore errors and pretend that everything went fine.\n // Showing an error would give a potential attacker information about which usernames exist (or not).\n // This way it's more difficult to exploit the process.\n } finally {\n runInAction(() => {\n this.authState = \"passwordResetCodeSent\";\n this.authData = { username };\n this.formLoading = false;\n });\n }\n }\n\n async resendPasswordResetCode(): Promise<void> {\n const username = this.authData?.username;\n if (this.authState !== \"passwordResetCodeSent\" || !username) {\n return;\n }\n\n await this.requestPasswordReset(username!);\n runInAction(() => {\n this.message = {\n title: \"Code Resent\",\n text: \"Password reset code has been resent to your email address. Please check your inbox!\",\n type: \"success\"\n };\n });\n }\n\n async confirmPasswordReset(code: string, password: string): Promise<void> {\n const username = this.authData?.username;\n if (!username) {\n return;\n }\n\n runInAction(() => {\n this.formLoading = true;\n this.message = null;\n });\n\n try {\n await confirmResetPassword({\n username,\n confirmationCode: code,\n newPassword: password\n });\n runInAction(() => {\n this.authState = \"signIn\";\n this.message = {\n title: \"Password Reset\",\n text: \"You can now sign in with your new password\",\n type: \"success\"\n };\n });\n } catch (error) {\n runInAction(() => {\n this.message = {\n title: \"Error\",\n text: error.message,\n type: \"danger\"\n };\n });\n } finally {\n runInAction(() => {\n this.formLoading = false;\n });\n }\n }\n\n async confirmTotpCode(code: string): Promise<void> {\n runInAction(() => {\n this.formLoading = true;\n this.message = null;\n });\n\n try {\n await confirmSignIn({ challengeResponse: code });\n await this.handleSignedIn();\n } catch (error) {\n runInAction(() => {\n this.message = {\n title: \"Verification Failed\",\n text: error.message,\n type: \"danger\"\n };\n });\n } finally {\n runInAction(() => {\n this.formLoading = false;\n });\n }\n }\n\n async verifyTotpSetup(code: string): Promise<void> {\n runInAction(() => {\n this.formLoading = true;\n this.message = null;\n });\n\n try {\n await confirmSignIn({ challengeResponse: code });\n await this.handleSignedIn();\n } catch (error) {\n runInAction(() => {\n this.message = {\n title: \"Setup Failed\",\n text: error.message,\n type: \"danger\"\n };\n });\n } finally {\n runInAction(() => {\n this.formLoading = false;\n });\n }\n }\n\n selectTenant(tenantId: string): void {\n runInAction(() => {\n this.isLoggingIn = true;\n });\n\n // Changing the tenant reloads the app, which logs in again on the selected tenant.\n this.tenantContext.setTenant(tenantId);\n }\n\n async signOut(): Promise<void> {\n try {\n await signOut();\n } finally {\n runInAction(() => {\n this.authState = \"signIn\";\n this.authData = null;\n this.message = null;\n this.tenants = [];\n });\n }\n }\n\n showSignIn(): void {\n this.authState = \"signIn\";\n this.authData = null;\n this.message = null;\n }\n\n showRequestPasswordResetCode(): void {\n this.authState = \"requestPasswordResetCode\";\n this.message = null;\n }\n\n showSetNewPassword(): void {\n this.authState = \"setNewPassword\";\n this.message = null;\n }\n\n // Private/internal methods\n private async handleSignedIn(): Promise<void> {\n runInAction(() => {\n this.isLoggingIn = true;\n });\n\n // While the app reloads on another tenant, the loader stays on.\n let switchingTenant = false;\n\n try {\n const result = await this.logInUseCase.execute({\n idTokenProvider: async () => {\n const session = await fetchAuthSession();\n const idToken = session.tokens?.idToken;\n if (!idToken) {\n throw new Error(\"No ID token available.\");\n }\n return idToken.toString();\n },\n logoutCallback: () => {\n signOut();\n runInAction(() => {\n this.authState = \"signIn\";\n this.authData = null;\n });\n }\n });\n\n switchingTenant = result.type === \"switchingTenant\";\n\n runInAction(() => {\n switch (result.type) {\n case \"loggedIn\":\n this.authState = \"signedIn\";\n break;\n case \"selectTenant\":\n this.tenants = result.tenants;\n this.authState = \"selectTenant\";\n break;\n case \"noTenantAccess\":\n this.authState = \"noTenantAccess\";\n break;\n }\n });\n } catch (error) {\n console.error(\"Error during sign in:\", error);\n\n // Sign out of Cognito, so the user can sign in again (with this or another account).\n try {\n await signOut();\n } catch {\n // The message below is what matters to the user.\n }\n\n runInAction(() => {\n this.authState = \"signIn\";\n this.message = {\n title: \"Login Failed\",\n text: error.message,\n type: \"danger\"\n };\n });\n } finally {\n if (!switchingTenant) {\n runInAction(() => {\n this.isLoggingIn = false;\n });\n }\n }\n }\n\n private async checkUrl(): Promise<void> {\n return this.checkSession();\n }\n\n private async checkSession(): Promise<void> {\n runInAction(() => {\n this.checkingSession = true;\n });\n\n try {\n const session = await fetchAuthSession();\n if (session.tokens) {\n // We don't need to `await`, we simply start a separate \"branch\" of execution.\n this.handleSignedIn();\n }\n } catch {\n // Not authenticated, stay on signIn\n } finally {\n runInAction(() => {\n this.checkingSession = false;\n });\n }\n }\n}\n\nexport const CognitoPresenter = CognitoPresenterAbstraction.createImplementation({\n implementation: CognitoPresenterImpl,\n dependencies: [\n IdentityContext,\n LogInUseCase,\n TenantContext,\n [CognitoSignInConfig, { optional: true }]\n ]\n});\n"],"names":["federatedDescription","CognitoPresenterImpl","identity","logInUseCase","tenantContext","signInConfig","undefined","makeAutoObservable","params","oauthConfig","config","runInAction","domain","process","Amplify","username","password","usernameOrPassword","result","signIn","nextStep","totpSetup","uri","error","message","requiredAttributes","confirmSignIn","resetPassword","code","confirmResetPassword","tenantId","signOut","switchingTenant","session","fetchAuthSession","idToken","Error","console","CognitoPresenter","CognitoPresenterAbstraction","IdentityContext","LogInUseCase","TenantContext","CognitoSignInConfig"],"mappings":";;;;;;;;AAuBA,MAAMA,uBACF;AAEJ,MAAMC;IAmBF,YACYC,QAAmC,EACnCC,YAAoC,EACpCC,aAAsC,EACtCC,YAAuD,CACjE;aAJUH,QAAQ,GAARA;aACAC,YAAY,GAAZA;aACAC,aAAa,GAAbA;aACAC,YAAY,GAAZA;aAtBJ,SAAS,GAAc;aACvB,QAAQ,GAAoB;aAC5B,OAAO,GAAuB;aAC9B,eAAe,GAAG;aAClB,WAAW,GAAG;aACd,WAAW,GAAG;aACd,WAAW,GAAG;aAEd,WAAW,GAAG;aACd,iBAAiB,GAAuBC;aACxC,qBAAqB,GAAG;aACxB,kBAAkB,GAA4C,EAAE;aAEhE,gBAAgB,GAAG;aACnB,aAAa,GAAG;aAEhB,OAAO,GAAa,EAAE;QAQ1BC,mBAAmB,IAAI;IAC3B;IAEA,IAAI,KAAK;QACL,MAAML,WAAW,IAAI,CAAC,QAAQ,CAAC,WAAW;QAE1C,OAAO;YACH,WAAW,IAAI,CAAC,SAAS;YACzB,iBAAiB,IAAI,CAAC,eAAe;YACrC,aAAa,IAAI,CAAC,WAAW;YAC7B,iBAAiBA,SAAS,eAAe;YAGzC,QAAQ;gBACJ,WAAW,IAAI,CAAC,WAAW;gBAC3B,SAAS,IAAI,CAAC,OAAO;gBACrB,OAAO,IAAI,CAAC,WAAW;gBACvB,aAAa,IAAI,CAAC,iBAAiB;gBACnC,uBAAuB,IAAI,CAAC,qBAAqB;gBACjD,oBAAoB,IAAI,CAAC,kBAAkB;YAC/C;YACA,0BAA0B;gBACtB,WAAW,IAAI,CAAC,WAAW;gBAC3B,SAAS,IAAI,CAAC,OAAO;YACzB;YACA,uBAAuB;gBACnB,WAAW,IAAI,CAAC,WAAW;gBAC3B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BAAgBtC;IAChB,cAAc;QACVuC;QACAC;QACAC;QACA;YAACC;YAAqB;gBAAE,UAAU;YAAK;SAAE;KAC5C;AACL"}
@@ -0,0 +1,180 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { Container } from "@webiny/di";
3
+ import { MainGraphQLClient } from "@webiny/app/features/mainGraphQLClient/index.js";
4
+ import { LocalStorage } from "@webiny/app/features/localStorage/index.js";
5
+ import { TenancyFeature } from "@webiny/app-admin/features/tenancy/feature.js";
6
+ import { SecurityFeature } from "@webiny/app-admin/features/security/SecurityFeature.js";
7
+ import { CognitoFeature } from "./feature.js";
8
+ const amplify = vi.hoisted(()=>({
9
+ signIn: vi.fn(),
10
+ signOut: vi.fn(),
11
+ fetchAuthSession: vi.fn()
12
+ }));
13
+ vi.mock("aws-amplify", ()=>({
14
+ Amplify: {
15
+ configure: vi.fn()
16
+ }
17
+ }));
18
+ vi.mock("aws-amplify/auth", ()=>({
19
+ signIn: amplify.signIn,
20
+ signOut: amplify.signOut,
21
+ fetchAuthSession: amplify.fetchAuthSession,
22
+ confirmSignIn: vi.fn(),
23
+ resetPassword: vi.fn(),
24
+ confirmResetPassword: vi.fn()
25
+ }));
26
+ const createLocalStorage = ()=>{
27
+ const values = new Map();
28
+ return {
29
+ get: (key)=>values.get(key),
30
+ set: (key, value)=>{
31
+ values.set(key, value);
32
+ },
33
+ remove: (key)=>{
34
+ values.delete(key);
35
+ },
36
+ clear: ()=>values.clear(),
37
+ keys: ()=>Array.from(values.keys())
38
+ };
39
+ };
40
+ const loginResponse = (login)=>({
41
+ security: {
42
+ login: {
43
+ data: login.data ?? null,
44
+ error: login.error ?? null
45
+ }
46
+ }
47
+ });
48
+ const tenantSelection = (tenants)=>loginResponse({
49
+ data: {
50
+ __typename: "SecurityLoginTenantSelection",
51
+ tenants
52
+ }
53
+ });
54
+ const identityDto = {
55
+ __typename: "SecurityIdentity",
56
+ id: "user-1",
57
+ type: "admin",
58
+ displayName: "User 1",
59
+ roles: [],
60
+ teams: [],
61
+ permissions: [
62
+ {
63
+ name: "*"
64
+ }
65
+ ],
66
+ profile: {
67
+ firstName: "",
68
+ lastName: "",
69
+ email: "user-1@webiny.local"
70
+ },
71
+ currentTenant: {
72
+ id: "root",
73
+ name: "Root"
74
+ },
75
+ defaultTenant: {
76
+ id: "root",
77
+ name: "Root"
78
+ }
79
+ };
80
+ describe("CognitoPresenter: signing in to a tenant", ()=>{
81
+ let container;
82
+ let execute;
83
+ const presenter = ()=>CognitoFeature.resolve(container).presenter;
84
+ const currentTenant = ()=>TenancyFeature.resolve(container).service.getCurrentTenant();
85
+ beforeEach(()=>{
86
+ vi.clearAllMocks();
87
+ amplify.signIn.mockResolvedValue({
88
+ nextStep: {
89
+ signInStep: "DONE"
90
+ }
91
+ });
92
+ amplify.signOut.mockResolvedValue(void 0);
93
+ amplify.fetchAuthSession.mockResolvedValue({
94
+ tokens: {
95
+ idToken: "token"
96
+ }
97
+ });
98
+ container = new Container();
99
+ execute = vi.fn();
100
+ container.registerInstance(LocalStorage, createLocalStorage());
101
+ container.registerInstance(MainGraphQLClient, {
102
+ execute
103
+ });
104
+ TenancyFeature.register(container);
105
+ SecurityFeature.register(container);
106
+ CognitoFeature.register(container);
107
+ });
108
+ it("signs the user in when they can access the current tenant", async ()=>{
109
+ execute.mockResolvedValue(loginResponse({
110
+ data: identityDto
111
+ }));
112
+ await presenter().signIn("user-1@webiny.local", "password");
113
+ expect(presenter().vm.authState).toBe("signedIn");
114
+ expect(presenter().vm.isAuthenticated).toBe(true);
115
+ });
116
+ it("keeps the loader on while the app reloads on the user's only tenant", async ()=>{
117
+ execute.mockResolvedValue(tenantSelection([
118
+ {
119
+ id: "acme",
120
+ name: "Acme"
121
+ }
122
+ ]));
123
+ await presenter().signIn("user-1@webiny.local", "password");
124
+ expect(presenter().vm.isLoggingIn).toBe(true);
125
+ expect(currentTenant()).toBe("acme");
126
+ expect(amplify.signOut).not.toHaveBeenCalled();
127
+ });
128
+ it("shows a tenant picker when the user can access several tenants, and picking one opens it", async ()=>{
129
+ const tenants = [
130
+ {
131
+ id: "acme",
132
+ name: "Acme"
133
+ },
134
+ {
135
+ id: "beta",
136
+ name: "Beta"
137
+ }
138
+ ];
139
+ execute.mockResolvedValue(tenantSelection(tenants));
140
+ await presenter().signIn("user-1@webiny.local", "password");
141
+ expect(presenter().vm.authState).toBe("selectTenant");
142
+ expect(presenter().vm.isLoggingIn).toBe(false);
143
+ expect(presenter().vm.selectTenant.tenants).toEqual(tenants);
144
+ presenter().selectTenant("beta");
145
+ expect(currentTenant()).toBe("beta");
146
+ expect(presenter().vm.isLoggingIn).toBe(true);
147
+ });
148
+ it("shows the no-access screen, and signing out returns to the sign-in form", async ()=>{
149
+ execute.mockResolvedValue(loginResponse({
150
+ error: {
151
+ code: "Security/Identity/NotAuthorized",
152
+ message: "Missing user profile!"
153
+ }
154
+ }));
155
+ await presenter().signIn("user-1@webiny.local", "password");
156
+ expect(presenter().vm.authState).toBe("noTenantAccess");
157
+ await presenter().signOut();
158
+ expect(amplify.signOut).toHaveBeenCalled();
159
+ expect(presenter().vm.authState).toBe("signIn");
160
+ expect(presenter().vm.signIn.message).toBeNull();
161
+ });
162
+ it("shows any other login error on the sign-in form instead of failing silently", async ()=>{
163
+ execute.mockResolvedValue(loginResponse({
164
+ data: {
165
+ ...identityDto,
166
+ permissions: []
167
+ }
168
+ }));
169
+ await presenter().signIn("user-1@webiny.local", "password");
170
+ expect(presenter().vm.authState).toBe("signIn");
171
+ expect(presenter().vm.signIn.message).toEqual({
172
+ title: "Login Failed",
173
+ text: "You have no permissions on this tenant!",
174
+ type: "danger"
175
+ });
176
+ expect(amplify.signOut).toHaveBeenCalled();
177
+ });
178
+ });
179
+
180
+ //# sourceMappingURL=CognitoPresenter.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin/presentation/Cognito/CognitoPresenter.test.js","sources":["../../../../src/admin/presentation/Cognito/CognitoPresenter.test.ts"],"sourcesContent":["import { describe, it, expect, vi, beforeEach } from \"vitest\";\nimport { Container } from \"@webiny/di\";\nimport { MainGraphQLClient } from \"@webiny/app/features/mainGraphQLClient/index.js\";\nimport { LocalStorage } from \"@webiny/app/features/localStorage/index.js\";\nimport { TenancyFeature } from \"@webiny/app-admin/features/tenancy/feature.js\";\nimport { SecurityFeature } from \"@webiny/app-admin/features/security/SecurityFeature.js\";\nimport { CognitoFeature } from \"./feature.js\";\n\nconst amplify = vi.hoisted(() => {\n return {\n signIn: vi.fn(),\n signOut: vi.fn(),\n fetchAuthSession: vi.fn()\n };\n});\n\nvi.mock(\"aws-amplify\", () => ({ Amplify: { configure: vi.fn() } }));\n\nvi.mock(\"aws-amplify/auth\", () => ({\n signIn: amplify.signIn,\n signOut: amplify.signOut,\n fetchAuthSession: amplify.fetchAuthSession,\n confirmSignIn: vi.fn(),\n resetPassword: vi.fn(),\n confirmResetPassword: vi.fn()\n}));\n\nconst createLocalStorage = (): LocalStorage.Interface => {\n const values = new Map<string, any>();\n return {\n get: key => values.get(key),\n set: (key, value) => {\n values.set(key, value);\n },\n remove: key => {\n values.delete(key);\n },\n clear: () => values.clear(),\n keys: () => Array.from(values.keys())\n };\n};\n\nconst loginResponse = (login: { data?: any; error?: any }) => {\n return { security: { login: { data: login.data ?? null, error: login.error ?? null } } };\n};\n\nconst tenantSelection = (tenants: { id: string; name: string }[]) => {\n return loginResponse({ data: { __typename: \"SecurityLoginTenantSelection\", tenants } });\n};\n\nconst identityDto = {\n __typename: \"SecurityIdentity\",\n id: \"user-1\",\n type: \"admin\",\n displayName: \"User 1\",\n roles: [],\n teams: [],\n permissions: [{ name: \"*\" }],\n profile: { firstName: \"\", lastName: \"\", email: \"user-1@webiny.local\" },\n currentTenant: { id: \"root\", name: \"Root\" },\n defaultTenant: { id: \"root\", name: \"Root\" }\n};\n\ndescribe(\"CognitoPresenter: signing in to a tenant\", () => {\n let container: Container;\n let execute: ReturnType<typeof vi.fn>;\n\n const presenter = () => CognitoFeature.resolve(container).presenter;\n const currentTenant = () => TenancyFeature.resolve(container).service.getCurrentTenant();\n\n beforeEach(() => {\n vi.clearAllMocks();\n amplify.signIn.mockResolvedValue({ nextStep: { signInStep: \"DONE\" } });\n amplify.signOut.mockResolvedValue(undefined);\n amplify.fetchAuthSession.mockResolvedValue({ tokens: { idToken: \"token\" } });\n\n container = new Container();\n execute = vi.fn();\n container.registerInstance(LocalStorage, createLocalStorage());\n container.registerInstance(MainGraphQLClient, {\n execute\n } as unknown as MainGraphQLClient.Interface);\n\n TenancyFeature.register(container);\n SecurityFeature.register(container);\n CognitoFeature.register(container);\n });\n\n it(\"signs the user in when they can access the current tenant\", async () => {\n execute.mockResolvedValue(loginResponse({ data: identityDto }));\n\n await presenter().signIn(\"user-1@webiny.local\", \"password\");\n\n expect(presenter().vm.authState).toBe(\"signedIn\");\n expect(presenter().vm.isAuthenticated).toBe(true);\n });\n\n it(\"keeps the loader on while the app reloads on the user's only tenant\", async () => {\n execute.mockResolvedValue(tenantSelection([{ id: \"acme\", name: \"Acme\" }]));\n\n await presenter().signIn(\"user-1@webiny.local\", \"password\");\n\n expect(presenter().vm.isLoggingIn).toBe(true);\n expect(currentTenant()).toBe(\"acme\");\n expect(amplify.signOut).not.toHaveBeenCalled();\n });\n\n it(\"shows a tenant picker when the user can access several tenants, and picking one opens it\", async () => {\n const tenants = [\n { id: \"acme\", name: \"Acme\" },\n { id: \"beta\", name: \"Beta\" }\n ];\n execute.mockResolvedValue(tenantSelection(tenants));\n\n await presenter().signIn(\"user-1@webiny.local\", \"password\");\n\n expect(presenter().vm.authState).toBe(\"selectTenant\");\n expect(presenter().vm.isLoggingIn).toBe(false);\n expect(presenter().vm.selectTenant.tenants).toEqual(tenants);\n\n presenter().selectTenant(\"beta\");\n\n expect(currentTenant()).toBe(\"beta\");\n expect(presenter().vm.isLoggingIn).toBe(true);\n });\n\n it(\"shows the no-access screen, and signing out returns to the sign-in form\", async () => {\n execute.mockResolvedValue(\n loginResponse({\n error: { code: \"Security/Identity/NotAuthorized\", message: \"Missing user profile!\" }\n })\n );\n\n await presenter().signIn(\"user-1@webiny.local\", \"password\");\n\n expect(presenter().vm.authState).toBe(\"noTenantAccess\");\n\n await presenter().signOut();\n\n expect(amplify.signOut).toHaveBeenCalled();\n expect(presenter().vm.authState).toBe(\"signIn\");\n expect(presenter().vm.signIn.message).toBeNull();\n });\n\n it(\"shows any other login error on the sign-in form instead of failing silently\", async () => {\n execute.mockResolvedValue(loginResponse({ data: { ...identityDto, permissions: [] } }));\n\n await presenter().signIn(\"user-1@webiny.local\", \"password\");\n\n expect(presenter().vm.authState).toBe(\"signIn\");\n expect(presenter().vm.signIn.message).toEqual({\n title: \"Login Failed\",\n text: \"You have no permissions on this tenant!\",\n type: \"danger\"\n });\n // The Cognito session is closed, so the user can sign in again.\n expect(amplify.signOut).toHaveBeenCalled();\n });\n});\n"],"names":["amplify","vi","createLocalStorage","values","Map","key","value","Array","loginResponse","login","tenantSelection","tenants","identityDto","describe","container","execute","presenter","CognitoFeature","currentTenant","TenancyFeature","beforeEach","undefined","Container","LocalStorage","MainGraphQLClient","SecurityFeature","it","expect"],"mappings":";;;;;;;AAQA,MAAMA,UAAUC,GAAG,OAAO,CAAC,IAChB;QACH,QAAQA,GAAG,EAAE;QACb,SAASA,GAAG,EAAE;QACd,kBAAkBA,GAAG,EAAE;IAC3B;AAGJA,GAAG,IAAI,CAAC,eAAe,IAAO;QAAE,SAAS;YAAE,WAAWA,GAAG,EAAE;QAAG;IAAE;AAEhEA,GAAG,IAAI,CAAC,oBAAoB,IAAO;QAC/B,QAAQD,QAAQ,MAAM;QACtB,SAASA,QAAQ,OAAO;QACxB,kBAAkBA,QAAQ,gBAAgB;QAC1C,eAAeC,GAAG,EAAE;QACpB,eAAeA,GAAG,EAAE;QACpB,sBAAsBA,GAAG,EAAE;IAC/B;AAEA,MAAMC,qBAAqB;IACvB,MAAMC,SAAS,IAAIC;IACnB,OAAO;QACH,KAAKC,CAAAA,MAAOF,OAAO,GAAG,CAACE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iBAAiB,CACrBP,cAAc;YACV,OAAO;gBAAE,MAAM;gBAAmC,SAAS;YAAwB;QACvF;QAGJ,MAAMQ,YAAY,MAAM,CAAC,uBAAuB;QAEhDW,OAAOX,YAAY,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC;QAEtC,MAAMA,YAAY,OAAO;QAEzBW,OAAO3B,QAAQ,OAAO,EAAE,gBAAgB;QACxC2B,OAAOX,YAAY,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC;QACtCW,OAAOX,YAAY,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ;IAClD;IAEAU,GAAG,+EAA+E;QAC9EX,QAAQ,iBAAiB,CAACP,cAAc;YAAE,MAAM;gBAAE,GAAGI,WAAW;gBAAE,aAAa,EAAE;YAAC;QAAE;QAEpF,MAAMI,YAAY,MAAM,CAAC,uBAAuB;QAEhDW,OAAOX,YAAY,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC;QACtCW,OAAOX,YAAY,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;YAC1C,OAAO;YACP,MAAM;YACN,MAAM;QACV;QAEAW,OAAO3B,QAAQ,OAAO,EAAE,gBAAgB;IAC5C;AACJ"}
@@ -1,5 +1,6 @@
1
1
  import type { IFederatedProvider } from "./CognitoSignInConfig.js";
2
- export type AuthState = "signIn" | "signedIn" | "signedOut" | "requestPasswordResetCode" | "passwordResetCodeSent" | "setNewPassword" | "requireNewPassword" | "confirmTotpCode" | "setupTotp";
2
+ import type { Tenant } from "@webiny/app-admin/features/tenancy/abstractions.js";
3
+ export type AuthState = "signIn" | "signedIn" | "signedOut" | "requestPasswordResetCode" | "passwordResetCodeSent" | "setNewPassword" | "requireNewPassword" | "confirmTotpCode" | "setupTotp" | "selectTenant" | "noTenantAccess";
3
4
  export interface AuthDataVerified {
4
5
  email?: string;
5
6
  phone_number?: string;
@@ -59,6 +60,9 @@ export interface SetupTotpVM {
59
60
  qrCodeUri: string;
60
61
  message: AuthMessage | null;
61
62
  }
63
+ export interface SelectTenantVM {
64
+ tenants: Tenant[];
65
+ }
62
66
  export interface ICognitoPresenter {
63
67
  vm: {
64
68
  authState: AuthState;
@@ -72,6 +76,7 @@ export interface ICognitoPresenter {
72
76
  setNewPassword: SetNewPasswordVM;
73
77
  confirmTotpCode: ConfirmTotpCodeVM;
74
78
  setupTotp: SetupTotpVM;
79
+ selectTenant: SelectTenantVM;
75
80
  };
76
81
  init(params: ICognitoInitParams): Promise<void>;
77
82
  signIn(username: string, password: string): Promise<void>;
@@ -81,6 +86,8 @@ export interface ICognitoPresenter {
81
86
  confirmPasswordReset(code: string, password: string): Promise<void>;
82
87
  confirmTotpCode(code: string): Promise<void>;
83
88
  verifyTotpSetup(code: string): Promise<void>;
89
+ selectTenant(tenantId: string): void;
90
+ signOut(): Promise<void>;
84
91
  showSignIn(): void;
85
92
  showRequestPasswordResetCode(): void;
86
93
  showSetNewPassword(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"admin/presentation/Cognito/abstractions.js","sources":["../../../../src/admin/presentation/Cognito/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { IFederatedProvider } from \"./CognitoSignInConfig.js\";\n\nexport type AuthState =\n | \"signIn\"\n | \"signedIn\"\n | \"signedOut\"\n | \"requestPasswordResetCode\"\n | \"passwordResetCodeSent\"\n | \"setNewPassword\"\n | \"requireNewPassword\"\n | \"confirmTotpCode\"\n | \"setupTotp\";\n\nexport interface AuthDataVerified {\n email?: string;\n phone_number?: string;\n}\n\nexport interface AuthDataUnverified {\n email?: string;\n phone_number?: string;\n}\n\nexport interface AuthData {\n username?: string;\n verified?: AuthDataVerified;\n unverified?: AuthDataUnverified;\n requiredAttributes?: string[];\n [key: string]:\n | string\n | null\n | boolean\n | undefined\n | string[]\n | AuthDataVerified\n | AuthDataUnverified;\n}\n\nexport interface AuthMessage {\n title: string;\n text: string;\n type: \"success\" | \"info\" | \"warning\" | \"danger\";\n}\n\nexport interface ICognitoInitParams {\n region: string;\n userPoolId: string;\n clientId: string;\n}\n\nexport interface SignInVM {\n isLoading: boolean;\n message: AuthMessage | null;\n title: string;\n description: string | undefined;\n allowCredentialsLogin: boolean;\n federatedProviders: IFederatedProvider[];\n}\n\nexport interface RequireNewPasswordVM {\n isLoading: boolean;\n requiredAttributes: string[];\n}\n\nexport interface RequestPasswordResetCodeVM {\n isLoading: boolean;\n message: AuthMessage | null;\n}\n\nexport interface PasswordResetCodeSentVM {\n isLoading: boolean;\n message: AuthMessage | null;\n}\n\nexport interface SetNewPasswordVM {\n isLoading: boolean;\n message: AuthMessage | null;\n}\n\nexport interface ConfirmTotpCodeVM {\n isLoading: boolean;\n message: AuthMessage | null;\n}\n\nexport interface SetupTotpVM {\n isLoading: boolean;\n sharedSecret: string;\n qrCodeUri: string;\n message: AuthMessage | null;\n}\n\nexport interface ICognitoPresenter {\n vm: {\n authState: AuthState;\n checkingSession: boolean;\n isLoggingIn: boolean;\n isAuthenticated: boolean;\n signIn: SignInVM;\n requireNewPassword: RequireNewPasswordVM;\n requestPasswordResetCode: RequestPasswordResetCodeVM;\n passwordResetCodeSent: PasswordResetCodeSentVM;\n setNewPassword: SetNewPasswordVM;\n confirmTotpCode: ConfirmTotpCodeVM;\n setupTotp: SetupTotpVM;\n };\n\n // Lifecycle\n init(params: ICognitoInitParams): Promise<void>;\n\n // Authentication actions\n signIn(username: string, password: string): Promise<void>;\n confirmNewPassword(password: string, requiredAttributes: any): Promise<void>;\n requestPasswordReset(username: string): Promise<void>;\n resendPasswordResetCode(): Promise<void>;\n confirmPasswordReset(code: string, password: string): Promise<void>;\n confirmTotpCode(code: string): Promise<void>;\n verifyTotpSetup(code: string): Promise<void>;\n\n // Navigation actions\n showSignIn(): void;\n showRequestPasswordResetCode(): void;\n showSetNewPassword(): void;\n}\n\nexport const CognitoPresenter = createAbstraction<ICognitoPresenter>(\"CognitoPresenter\");\n\nexport namespace CognitoPresenter {\n export type Interface = ICognitoPresenter;\n}\n"],"names":["CognitoPresenter","createAbstraction"],"mappings":";AA6HO,MAAMA,mBAAmBC,kBAAqC"}
1
+ {"version":3,"file":"admin/presentation/Cognito/abstractions.js","sources":["../../../../src/admin/presentation/Cognito/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { IFederatedProvider } from \"./CognitoSignInConfig.js\";\nimport type { Tenant } from \"@webiny/app-admin/features/tenancy/abstractions.js\";\n\nexport type AuthState =\n | \"signIn\"\n | \"signedIn\"\n | \"signedOut\"\n | \"requestPasswordResetCode\"\n | \"passwordResetCodeSent\"\n | \"setNewPassword\"\n | \"requireNewPassword\"\n | \"confirmTotpCode\"\n | \"setupTotp\"\n | \"selectTenant\"\n | \"noTenantAccess\";\n\nexport interface AuthDataVerified {\n email?: string;\n phone_number?: string;\n}\n\nexport interface AuthDataUnverified {\n email?: string;\n phone_number?: string;\n}\n\nexport interface AuthData {\n username?: string;\n verified?: AuthDataVerified;\n unverified?: AuthDataUnverified;\n requiredAttributes?: string[];\n [key: string]:\n | string\n | null\n | boolean\n | undefined\n | string[]\n | AuthDataVerified\n | AuthDataUnverified;\n}\n\nexport interface AuthMessage {\n title: string;\n text: string;\n type: \"success\" | \"info\" | \"warning\" | \"danger\";\n}\n\nexport interface ICognitoInitParams {\n region: string;\n userPoolId: string;\n clientId: string;\n}\n\nexport interface SignInVM {\n isLoading: boolean;\n message: AuthMessage | null;\n title: string;\n description: string | undefined;\n allowCredentialsLogin: boolean;\n federatedProviders: IFederatedProvider[];\n}\n\nexport interface RequireNewPasswordVM {\n isLoading: boolean;\n requiredAttributes: string[];\n}\n\nexport interface RequestPasswordResetCodeVM {\n isLoading: boolean;\n message: AuthMessage | null;\n}\n\nexport interface PasswordResetCodeSentVM {\n isLoading: boolean;\n message: AuthMessage | null;\n}\n\nexport interface SetNewPasswordVM {\n isLoading: boolean;\n message: AuthMessage | null;\n}\n\nexport interface ConfirmTotpCodeVM {\n isLoading: boolean;\n message: AuthMessage | null;\n}\n\nexport interface SetupTotpVM {\n isLoading: boolean;\n sharedSecret: string;\n qrCodeUri: string;\n message: AuthMessage | null;\n}\n\nexport interface SelectTenantVM {\n tenants: Tenant[];\n}\n\nexport interface ICognitoPresenter {\n vm: {\n authState: AuthState;\n checkingSession: boolean;\n isLoggingIn: boolean;\n isAuthenticated: boolean;\n signIn: SignInVM;\n requireNewPassword: RequireNewPasswordVM;\n requestPasswordResetCode: RequestPasswordResetCodeVM;\n passwordResetCodeSent: PasswordResetCodeSentVM;\n setNewPassword: SetNewPasswordVM;\n confirmTotpCode: ConfirmTotpCodeVM;\n setupTotp: SetupTotpVM;\n selectTenant: SelectTenantVM;\n };\n\n // Lifecycle\n init(params: ICognitoInitParams): Promise<void>;\n\n // Authentication actions\n signIn(username: string, password: string): Promise<void>;\n confirmNewPassword(password: string, requiredAttributes: any): Promise<void>;\n requestPasswordReset(username: string): Promise<void>;\n resendPasswordResetCode(): Promise<void>;\n confirmPasswordReset(code: string, password: string): Promise<void>;\n confirmTotpCode(code: string): Promise<void>;\n verifyTotpSetup(code: string): Promise<void>;\n selectTenant(tenantId: string): void;\n signOut(): Promise<void>;\n\n // Navigation actions\n showSignIn(): void;\n showRequestPasswordResetCode(): void;\n showSetNewPassword(): void;\n}\n\nexport const CognitoPresenter = createAbstraction<ICognitoPresenter>(\"CognitoPresenter\");\n\nexport namespace CognitoPresenter {\n export type Interface = ICognitoPresenter;\n}\n"],"names":["CognitoPresenter","createAbstraction"],"mappings":";AAuIO,MAAMA,mBAAmBC,kBAAqC"}