@webiny/cognito 6.3.0 → 6.4.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cognito.js +23 -24
- package/Cognito.js.map +1 -1
- package/admin/Cognito.js +35 -41
- package/admin/Cognito.js.map +1 -1
- package/admin/CognitoLogin.js +8 -13
- package/admin/CognitoLogin.js.map +1 -1
- package/admin/Extension.js +17 -16
- package/admin/Extension.js.map +1 -1
- package/admin/SecurityPermission.js +11 -14
- package/admin/SecurityPermission.js.map +1 -1
- package/admin/domain/permissionsSchema.js +14 -9
- package/admin/domain/permissionsSchema.js.map +1 -1
- package/admin/features/permissions/abstractions.js +2 -1
- package/admin/features/permissions/abstractions.js.map +1 -1
- package/admin/features/permissions/feature.js +2 -1
- package/admin/features/permissions/feature.js.map +1 -1
- package/admin/federatedIdentityProviders.js +7 -6
- package/admin/federatedIdentityProviders.js.map +1 -1
- package/admin/presentation/Cognito/CognitoLoginScreen.js +39 -42
- package/admin/presentation/Cognito/CognitoLoginScreen.js.map +1 -1
- package/admin/presentation/Cognito/CognitoPresenter.js +250 -275
- package/admin/presentation/Cognito/CognitoPresenter.js.map +1 -1
- package/admin/presentation/Cognito/abstractions.js +2 -1
- package/admin/presentation/Cognito/abstractions.js.map +1 -1
- package/admin/presentation/Cognito/components/Divider.js +12 -13
- package/admin/presentation/Cognito/components/Divider.js.map +1 -1
- package/admin/presentation/Cognito/components/FederatedLogin.js +24 -29
- package/admin/presentation/Cognito/components/FederatedLogin.js.map +1 -1
- package/admin/presentation/Cognito/components/FederatedProviders.js +7 -10
- package/admin/presentation/Cognito/components/FederatedProviders.js.map +1 -1
- package/admin/presentation/Cognito/components/FooterSignIn.js +9 -12
- package/admin/presentation/Cognito/components/FooterSignIn.js.map +1 -1
- package/admin/presentation/Cognito/components/PasswordResetCodeSent.js +33 -37
- package/admin/presentation/Cognito/components/PasswordResetCodeSent.js.map +1 -1
- package/admin/presentation/Cognito/components/RequestPasswordResetCode.js +35 -39
- package/admin/presentation/Cognito/components/RequestPasswordResetCode.js.map +1 -1
- package/admin/presentation/Cognito/components/RequireNewPassword.js +44 -48
- package/admin/presentation/Cognito/components/RequireNewPassword.js.map +1 -1
- package/admin/presentation/Cognito/components/SetNewPassword.js +70 -71
- package/admin/presentation/Cognito/components/SetNewPassword.js.map +1 -1
- package/admin/presentation/Cognito/components/SignIn.js +52 -59
- package/admin/presentation/Cognito/components/SignIn.js.map +1 -1
- package/admin/presentation/Cognito/components/View.js +41 -60
- package/admin/presentation/Cognito/components/View.js.map +1 -1
- package/admin/presentation/Cognito/feature.js +12 -11
- package/admin/presentation/Cognito/feature.js.map +1 -1
- package/admin/presentation/shared/createPasswordValidator.js +13 -24
- package/admin/presentation/shared/createPasswordValidator.js.map +1 -1
- package/admin/presentation/shared/usePasswordValidator.js +11 -10
- package/admin/presentation/shared/usePasswordValidator.js.map +1 -1
- package/admin/presentation/userMenu/AccountDetails.js +15 -18
- package/admin/presentation/userMenu/AccountDetails.js.map +1 -1
- package/admin/presentation/userMenu/useIsDefaultTenant.js +5 -11
- package/admin/presentation/userMenu/useIsDefaultTenant.js.map +1 -1
- package/admin/routes.js +16 -17
- package/admin/routes.js.map +1 -1
- package/admin/ui/UserItem.js +0 -3
- package/admin/ui/components/AvatarImage/AvatarImage.js +25 -37
- package/admin/ui/components/AvatarImage/AvatarImage.js.map +1 -1
- package/admin/ui/components/AvatarImage/AvatarImagePreview.js +49 -51
- package/admin/ui/components/AvatarImage/AvatarImagePreview.js.map +1 -1
- package/admin/ui/components/AvatarImage/AvatarImageTrigger.js +25 -26
- package/admin/ui/components/AvatarImage/AvatarImageTrigger.js.map +1 -1
- package/admin/ui/components/AvatarImage/index.js +0 -2
- package/admin/ui/views/Account/Account.js +117 -130
- package/admin/ui/views/Account/Account.js.map +1 -1
- package/admin/ui/views/Account/graphql.js +5 -4
- package/admin/ui/views/Account/graphql.js.map +1 -1
- package/admin/ui/views/Account/index.js +0 -2
- package/admin/ui/views/Users/UsersDataList.js +146 -159
- package/admin/ui/views/Users/UsersDataList.js.map +1 -1
- package/admin/ui/views/Users/UsersForm.js +151 -162
- package/admin/ui/views/Users/UsersForm.js.map +1 -1
- package/admin/ui/views/Users/UsersView.js +9 -9
- package/admin/ui/views/Users/UsersView.js.map +1 -1
- package/admin/ui/views/Users/components/DeleteAction.js +23 -30
- package/admin/ui/views/Users/components/DeleteAction.js.map +1 -1
- package/admin/ui/views/Users/graphql.js +9 -10
- package/admin/ui/views/Users/graphql.js.map +1 -1
- package/admin/ui/views/Users/hooks/useUserForm.js +104 -114
- package/admin/ui/views/Users/hooks/useUserForm.js.map +1 -1
- package/admin/ui/views/Users/search.js +21 -0
- package/admin/ui/views/Users/search.js.map +1 -0
- package/admin/ui/views/utils.js +9 -7
- package/admin/ui/views/utils.js.map +1 -1
- package/api/CognitoApiFeature.js +15 -17
- package/api/CognitoApiFeature.js.map +1 -1
- package/api/domain/Username.js +5 -4
- package/api/domain/Username.js.map +1 -1
- package/api/domain/errors.js +37 -56
- package/api/domain/errors.js.map +1 -1
- package/api/features/CognitoIdp/CognitoIdentityProvider.js +49 -51
- package/api/features/CognitoIdp/CognitoIdentityProvider.js.map +1 -1
- package/api/features/CognitoIdp/abstractions.js +2 -1
- package/api/features/CognitoIdp/abstractions.js.map +1 -1
- package/api/features/CognitoIdp/feature.js +6 -5
- package/api/features/CognitoIdp/feature.js.map +1 -1
- package/api/features/CognitoIdp/index.js +0 -2
- package/api/features/CognitoService/CognitoService.js +93 -83
- package/api/features/CognitoService/CognitoService.js.map +1 -1
- package/api/features/CognitoService/abstractions.js +3 -5
- package/api/features/CognitoService/abstractions.js.map +1 -1
- package/api/features/CognitoService/feature.js +7 -6
- package/api/features/CognitoService/feature.js.map +1 -1
- package/api/features/CognitoService/index.js +0 -2
- package/api/features/CreateUser/CreateUserUseCase.js +62 -88
- package/api/features/CreateUser/CreateUserUseCase.js.map +1 -1
- package/api/features/CreateUser/abstractions.js +2 -1
- package/api/features/CreateUser/abstractions.js.map +1 -1
- package/api/features/CreateUser/feature.js +6 -5
- package/api/features/CreateUser/feature.js.map +1 -1
- package/api/features/CreateUser/index.js +0 -2
- package/api/features/CreateUser/schema.js +14 -13
- package/api/features/CreateUser/schema.js.map +1 -1
- package/api/features/DeleteUser/DeleteUserUseCase.js +34 -41
- package/api/features/DeleteUser/DeleteUserUseCase.js.map +1 -1
- package/api/features/DeleteUser/abstractions.js +2 -1
- package/api/features/DeleteUser/abstractions.js.map +1 -1
- package/api/features/DeleteUser/feature.js +6 -5
- package/api/features/DeleteUser/feature.js.map +1 -1
- package/api/features/DeleteUser/index.js +0 -2
- package/api/features/UpdateUser/UpdateUserUseCase.js +49 -71
- package/api/features/UpdateUser/UpdateUserUseCase.js.map +1 -1
- package/api/features/UpdateUser/abstractions.js +2 -1
- package/api/features/UpdateUser/abstractions.js.map +1 -1
- package/api/features/UpdateUser/feature.js +6 -5
- package/api/features/UpdateUser/feature.js.map +1 -1
- package/api/features/UpdateUser/index.js +0 -2
- package/api/features/UpdateUser/schema.js +13 -12
- package/api/features/UpdateUser/schema.js.map +1 -1
- package/api/features/UserInstaller/UserInstaller.js +36 -36
- package/api/features/UserInstaller/UserInstaller.js.map +1 -1
- package/api/features/UserInstaller/feature.js +6 -5
- package/api/features/UserInstaller/feature.js.map +1 -1
- package/api/graphql/user.gql.js +83 -107
- package/api/graphql/user.gql.js.map +1 -1
- package/index.js +0 -2
- package/package.json +22 -23
- package/static/svg/search.43fa797c.svg +20 -0
- package/admin/ui/UserItem.js.map +0 -1
- package/admin/ui/components/AvatarImage/index.js.map +0 -1
- package/admin/ui/views/Account/index.js.map +0 -1
- package/api/features/CognitoIdp/index.js.map +0 -1
- package/api/features/CognitoService/index.js.map +0 -1
- package/api/features/CreateUser/index.js.map +0 -1
- package/api/features/DeleteUser/index.js.map +0 -1
- package/api/features/UpdateUser/index.js.map +0 -1
- package/index.js.map +0 -1
|
@@ -1,61 +1,59 @@
|
|
|
1
1
|
import { OidcIdentityProvider } from "@webiny/api-core/idp";
|
|
2
2
|
import { CognitoIdpConfig } from "./abstractions.js";
|
|
3
3
|
class CognitoIdentityProviderImpl {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
isApplicable(token) {
|
|
12
|
-
const issuer = token.iss;
|
|
13
|
-
if (!issuer) {
|
|
14
|
-
return false;
|
|
4
|
+
constructor(config){
|
|
5
|
+
this.config = config;
|
|
6
|
+
const region = String(process.env.COGNITO_REGION);
|
|
7
|
+
const userPoolId = String(process.env.COGNITO_USER_POOL_ID);
|
|
8
|
+
this.clientId = String(process.env.COGNITO_CLIENT_ID);
|
|
9
|
+
this.issuer = `https://cognito-idp.${region}.amazonaws.com/${userPoolId}`;
|
|
15
10
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (customIdentity) {
|
|
21
|
-
return {
|
|
22
|
-
...customIdentity,
|
|
23
|
-
type: "admin",
|
|
24
|
-
profile: {
|
|
25
|
-
...customIdentity,
|
|
26
|
-
external: false
|
|
27
|
-
}
|
|
28
|
-
};
|
|
11
|
+
isApplicable(token) {
|
|
12
|
+
const issuer = token.iss;
|
|
13
|
+
if (!issuer) return false;
|
|
14
|
+
return issuer === this.issuer;
|
|
29
15
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
16
|
+
async getIdentity(token) {
|
|
17
|
+
const customIdentity = this.config ? await this.config.getIdentity(token) : null;
|
|
18
|
+
if (customIdentity) return {
|
|
19
|
+
...customIdentity,
|
|
20
|
+
type: "admin",
|
|
21
|
+
profile: {
|
|
22
|
+
...customIdentity,
|
|
23
|
+
external: false
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const customId = token["custom:id"];
|
|
27
|
+
const givenName = token["given_name"];
|
|
28
|
+
const familyName = token["family_name"];
|
|
29
|
+
const email = token["email"];
|
|
30
|
+
return {
|
|
31
|
+
id: customId || token.sub || "",
|
|
32
|
+
displayName: `${givenName || ""} ${familyName || ""}`.trim() || email || "Unknown User",
|
|
33
|
+
type: "admin",
|
|
34
|
+
profile: {
|
|
35
|
+
email: email || "",
|
|
36
|
+
firstName: givenName || "",
|
|
37
|
+
lastName: familyName || "",
|
|
38
|
+
external: false
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async verifyTokenClaims(token) {
|
|
43
|
+
if (this.config?.verifyTokenClaims) await this.config.verifyTokenClaims(token);
|
|
51
44
|
}
|
|
52
|
-
}
|
|
53
45
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
46
|
+
const CognitoIdentityProvider = OidcIdentityProvider.createImplementation({
|
|
47
|
+
implementation: CognitoIdentityProviderImpl,
|
|
48
|
+
dependencies: [
|
|
49
|
+
[
|
|
50
|
+
CognitoIdpConfig,
|
|
51
|
+
{
|
|
52
|
+
optional: true
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
]
|
|
59
56
|
});
|
|
57
|
+
export { CognitoIdentityProvider };
|
|
60
58
|
|
|
61
59
|
//# sourceMappingURL=CognitoIdentityProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"api/features/CognitoIdp/CognitoIdentityProvider.js","sources":["../../../../src/api/features/CognitoIdp/CognitoIdentityProvider.ts"],"sourcesContent":["import { OidcIdentityProvider } from \"@webiny/api-core/idp\";\nimport { CognitoIdpConfig } from \"./abstractions.js\";\n\nclass CognitoIdentityProviderImpl implements OidcIdentityProvider.Interface {\n public clientId: string;\n public issuer: string;\n\n constructor(private config: CognitoIdpConfig.Interface | undefined) {\n const region = String(process.env.COGNITO_REGION);\n const userPoolId = String(process.env.COGNITO_USER_POOL_ID);\n this.clientId = String(process.env.COGNITO_CLIENT_ID);\n this.issuer = `https://cognito-idp.${region}.amazonaws.com/${userPoolId}`;\n }\n\n isApplicable(token: OidcIdentityProvider.JwtPayload) {\n const issuer = token.iss as string;\n if (!issuer) {\n return false;\n }\n\n return issuer === this.issuer;\n }\n\n async getIdentity(\n token: OidcIdentityProvider.JwtPayload\n ): Promise<OidcIdentityProvider.IdentityData> {\n const customIdentity = this.config ? await this.config.getIdentity(token) : null;\n\n if (customIdentity) {\n return {\n ...customIdentity,\n type: \"admin\",\n profile: {\n ...customIdentity,\n external: false\n }\n };\n }\n\n // Default identity\n const customId = token[\"custom:id\"] as string | undefined;\n const givenName = token[\"given_name\"] as string | undefined;\n const familyName = token[\"family_name\"] as string | undefined;\n const email = token[\"email\"] as string | undefined;\n\n return {\n id: customId || token.sub || \"\",\n displayName: `${givenName || \"\"} ${familyName || \"\"}`.trim() || email || \"Unknown User\",\n type: \"admin\",\n profile: {\n email: email || \"\",\n firstName: givenName || \"\",\n lastName: familyName || \"\",\n external: false\n }\n };\n }\n\n async verifyTokenClaims(token: OidcIdentityProvider.JwtPayload): Promise<void> {\n if (this.config?.verifyTokenClaims) {\n await this.config.verifyTokenClaims(token);\n }\n }\n}\n\nexport const CognitoIdentityProvider = OidcIdentityProvider.createImplementation({\n implementation: CognitoIdentityProviderImpl,\n dependencies: [[CognitoIdpConfig, { optional: true }]]\n});\n"],"names":["CognitoIdentityProviderImpl","config","region","String","process","userPoolId","token","issuer","customIdentity","customId","givenName","familyName","email","CognitoIdentityProvider","OidcIdentityProvider","CognitoIdpConfig"],"mappings":";;AAGA,MAAMA;IAIF,YAAoBC,MAA8C,CAAE;aAAhDA,MAAM,GAANA;QAChB,MAAMC,SAASC,OAAOC,QAAQ,GAAG,CAAC,cAAc;QAChD,MAAMC,aAAaF,OAAOC,QAAQ,GAAG,CAAC,oBAAoB;QAC1D,IAAI,CAAC,QAAQ,GAAGD,OAAOC,QAAQ,GAAG,CAAC,iBAAiB;QACpD,IAAI,CAAC,MAAM,GAAG,CAAC,oBAAoB,EAAEF,OAAO,eAAe,EAAEG,YAAY;IAC7E;IAEA,aAAaC,KAAsC,EAAE;QACjD,MAAMC,SAASD,MAAM,GAAG;QACxB,IAAI,CAACC,QACD,OAAO;QAGX,OAAOA,WAAW,IAAI,CAAC,MAAM;IACjC;IAEA,MAAM,YACFD,KAAsC,EACI;QAC1C,MAAME,iBAAiB,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAACF,SAAS;QAE5E,IAAIE,gBACA,OAAO;YACH,GAAGA,cAAc;YACjB,MAAM;YACN,SAAS;gBACL,GAAGA,cAAc;gBACjB,UAAU;YACd;QACJ;QAIJ,MAAMC,WAAWH,KAAK,CAAC,YAAY;QACnC,MAAMI,YAAYJ,KAAK,CAAC,aAAa;QACrC,MAAMK,aAAaL,KAAK,CAAC,cAAc;QACvC,MAAMM,QAAQN,KAAK,CAAC,QAAQ;QAE5B,OAAO;YACH,IAAIG,YAAYH,MAAM,GAAG,IAAI;YAC7B,aAAa,GAAGI,aAAa,GAAG,CAAC,EAAEC,cAAc,IAAI,CAAC,IAAI,MAAMC,SAAS;YACzE,MAAM;YACN,SAAS;gBACL,OAAOA,SAAS;gBAChB,WAAWF,aAAa;gBACxB,UAAUC,cAAc;gBACxB,UAAU;YACd;QACJ;IACJ;IAEA,MAAM,kBAAkBL,KAAsC,EAAiB;QAC3E,IAAI,IAAI,CAAC,MAAM,EAAE,mBACb,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAACA;IAE5C;AACJ;AAEO,MAAMO,0BAA0BC,qBAAqB,oBAAoB,CAAC;IAC7E,gBAAgBd;IAChB,cAAc;QAAC;YAACe;YAAkB;gBAAE,UAAU;YAAK;SAAE;KAAC;AAC1D"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
|
|
2
|
+
const CognitoIdpConfig = createAbstraction("CognitoIdpConfig");
|
|
3
|
+
export { CognitoIdpConfig };
|
|
3
4
|
|
|
4
5
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"api/features/CognitoIdp/abstractions.js","sources":["../../../../src/api/features/CognitoIdp/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type jwt from \"jsonwebtoken\";\nimport type { IdentityData } from \"@webiny/api-core/idp\";\n\nexport type CognitoIdentity = Omit<IdentityData, \"type\"> & {\n profile: Omit<IdentityData[\"profile\"], \"external\">;\n};\n\nexport interface ICognitoIdpConfig {\n getIdentity(token: jwt.JwtPayload): Promise<CognitoIdentity> | CognitoIdentity;\n verifyTokenClaims?(token: jwt.JwtPayload): Promise<void> | void;\n}\n\nexport const CognitoIdpConfig = createAbstraction<ICognitoIdpConfig>(\"CognitoIdpConfig\");\n\nexport namespace CognitoIdpConfig {\n export type Interface = ICognitoIdpConfig;\n export type IdentityData = CognitoIdentity;\n export type JwtPayload = jwt.JwtPayload;\n}\n"],"names":["CognitoIdpConfig","createAbstraction"],"mappings":";AAaO,MAAMA,mBAAmBC,kBAAqC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { CognitoIdentityProvider } from "./CognitoIdentityProvider.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const CognitoIdpFeature = createFeature({
|
|
4
|
+
name: "CognitoIdp",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(CognitoIdentityProvider).inSingletonScope();
|
|
7
|
+
}
|
|
8
8
|
});
|
|
9
|
+
export { CognitoIdpFeature };
|
|
9
10
|
|
|
10
11
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"api/features/CognitoIdp/feature.js","sources":["../../../../src/api/features/CognitoIdp/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CognitoIdentityProvider } from \"./CognitoIdentityProvider.js\";\n\nexport const CognitoIdpFeature = createFeature({\n name: \"CognitoIdp\",\n register(container) {\n container.register(CognitoIdentityProvider).inSingletonScope();\n }\n});\n"],"names":["CognitoIdpFeature","createFeature","container","CognitoIdentityProvider"],"mappings":";;AAGO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,yBAAyB,gBAAgB;IAChE;AACJ"}
|
|
@@ -1,90 +1,100 @@
|
|
|
1
1
|
import { CognitoIdentityProvider } from "@webiny/aws-sdk/client-cognito-identity-provider/index.js";
|
|
2
|
-
import { CognitoConfig, CognitoService
|
|
2
|
+
import { CognitoConfig, CognitoService } from "./abstractions.js";
|
|
3
3
|
class CognitoServiceImpl {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
constructor(config){
|
|
5
|
+
this.config = config;
|
|
6
|
+
this.cognito = new CognitoIdentityProvider({
|
|
7
|
+
region: config.region
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
async userExists(username) {
|
|
11
|
+
try {
|
|
12
|
+
await this.cognito.adminGetUser({
|
|
13
|
+
Username: username,
|
|
14
|
+
UserPoolId: this.config.userPoolId
|
|
15
|
+
});
|
|
16
|
+
return true;
|
|
17
|
+
} catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async createUser(params) {
|
|
22
|
+
const createUserParams = {
|
|
23
|
+
UserPoolId: this.config.userPoolId,
|
|
24
|
+
Username: params.username,
|
|
25
|
+
DesiredDeliveryMediums: [],
|
|
26
|
+
ForceAliasCreation: false,
|
|
27
|
+
MessageAction: "SUPPRESS",
|
|
28
|
+
TemporaryPassword: params.temporaryPassword,
|
|
29
|
+
UserAttributes: [
|
|
30
|
+
{
|
|
31
|
+
Name: "given_name",
|
|
32
|
+
Value: params.attributes.givenName || ""
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
Name: "family_name",
|
|
36
|
+
Value: params.attributes.familyName || ""
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
Name: "preferred_username",
|
|
40
|
+
Value: params.attributes.preferredUsername
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
Name: "email",
|
|
44
|
+
Value: params.attributes.email
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
Name: "custom:id",
|
|
48
|
+
Value: params.attributes.customId
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
await this.cognito.adminCreateUser(createUserParams);
|
|
53
|
+
}
|
|
54
|
+
async setEmailVerified(username) {
|
|
55
|
+
await this.cognito.adminUpdateUserAttributes({
|
|
56
|
+
UserPoolId: this.config.userPoolId,
|
|
57
|
+
Username: username,
|
|
58
|
+
UserAttributes: [
|
|
59
|
+
{
|
|
60
|
+
Name: "email_verified",
|
|
61
|
+
Value: "true"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async setPermanentPassword(username, password) {
|
|
67
|
+
await this.cognito.adminSetUserPassword({
|
|
68
|
+
Permanent: true,
|
|
69
|
+
Password: password,
|
|
70
|
+
Username: username,
|
|
71
|
+
UserPoolId: this.config.userPoolId
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async updateUserAttributes(username, attributes) {
|
|
75
|
+
const userAttributes = Object.entries(attributes).map(([name, value])=>({
|
|
76
|
+
Name: name,
|
|
77
|
+
Value: value
|
|
78
|
+
}));
|
|
79
|
+
await this.cognito.adminUpdateUserAttributes({
|
|
80
|
+
UserPoolId: this.config.userPoolId,
|
|
81
|
+
Username: username,
|
|
82
|
+
UserAttributes: userAttributes
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async deleteUser(username) {
|
|
86
|
+
await this.cognito.adminDeleteUser({
|
|
87
|
+
UserPoolId: this.config.userPoolId,
|
|
88
|
+
Username: username
|
|
89
|
+
});
|
|
20
90
|
}
|
|
21
|
-
}
|
|
22
|
-
async createUser(params) {
|
|
23
|
-
const createUserParams = {
|
|
24
|
-
UserPoolId: this.config.userPoolId,
|
|
25
|
-
Username: params.username,
|
|
26
|
-
DesiredDeliveryMediums: [],
|
|
27
|
-
ForceAliasCreation: false,
|
|
28
|
-
MessageAction: "SUPPRESS",
|
|
29
|
-
TemporaryPassword: params.temporaryPassword,
|
|
30
|
-
UserAttributes: [{
|
|
31
|
-
Name: "given_name",
|
|
32
|
-
Value: params.attributes.givenName || ""
|
|
33
|
-
}, {
|
|
34
|
-
Name: "family_name",
|
|
35
|
-
Value: params.attributes.familyName || ""
|
|
36
|
-
}, {
|
|
37
|
-
Name: "preferred_username",
|
|
38
|
-
Value: params.attributes.preferredUsername
|
|
39
|
-
}, {
|
|
40
|
-
Name: "email",
|
|
41
|
-
Value: params.attributes.email
|
|
42
|
-
}, {
|
|
43
|
-
Name: "custom:id",
|
|
44
|
-
Value: params.attributes.customId
|
|
45
|
-
}]
|
|
46
|
-
};
|
|
47
|
-
await this.cognito.adminCreateUser(createUserParams);
|
|
48
|
-
}
|
|
49
|
-
async setEmailVerified(username) {
|
|
50
|
-
await this.cognito.adminUpdateUserAttributes({
|
|
51
|
-
UserPoolId: this.config.userPoolId,
|
|
52
|
-
Username: username,
|
|
53
|
-
UserAttributes: [{
|
|
54
|
-
Name: "email_verified",
|
|
55
|
-
Value: "true"
|
|
56
|
-
}]
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
async setPermanentPassword(username, password) {
|
|
60
|
-
await this.cognito.adminSetUserPassword({
|
|
61
|
-
Permanent: true,
|
|
62
|
-
Password: password,
|
|
63
|
-
Username: username,
|
|
64
|
-
UserPoolId: this.config.userPoolId
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
async updateUserAttributes(username, attributes) {
|
|
68
|
-
const userAttributes = Object.entries(attributes).map(([name, value]) => ({
|
|
69
|
-
Name: name,
|
|
70
|
-
Value: value
|
|
71
|
-
}));
|
|
72
|
-
await this.cognito.adminUpdateUserAttributes({
|
|
73
|
-
UserPoolId: this.config.userPoolId,
|
|
74
|
-
Username: username,
|
|
75
|
-
UserAttributes: userAttributes
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
async deleteUser(username) {
|
|
79
|
-
await this.cognito.adminDeleteUser({
|
|
80
|
-
UserPoolId: this.config.userPoolId,
|
|
81
|
-
Username: username
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
91
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
92
|
+
const CognitoService_CognitoService = CognitoService.createImplementation({
|
|
93
|
+
implementation: CognitoServiceImpl,
|
|
94
|
+
dependencies: [
|
|
95
|
+
CognitoConfig
|
|
96
|
+
]
|
|
88
97
|
});
|
|
98
|
+
export { CognitoService_CognitoService as CognitoService };
|
|
89
99
|
|
|
90
100
|
//# sourceMappingURL=CognitoService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"api/features/CognitoService/CognitoService.js","sources":["../../../../src/api/features/CognitoService/CognitoService.ts"],"sourcesContent":["import type { AdminCreateUserRequest } from \"@webiny/aws-sdk/client-cognito-identity-provider/index.js\";\nimport { CognitoIdentityProvider } from \"@webiny/aws-sdk/client-cognito-identity-provider/index.js\";\nimport { CognitoConfig, CognitoService as ServiceAbstraction } from \"./abstractions.js\";\n\nclass CognitoServiceImpl implements ServiceAbstraction.Interface {\n private cognito: CognitoIdentityProvider;\n\n constructor(private config: CognitoConfig.Interface) {\n this.cognito = new CognitoIdentityProvider({ region: config.region });\n }\n\n async userExists(username: string): Promise<boolean> {\n try {\n await this.cognito.adminGetUser({\n Username: username,\n UserPoolId: this.config.userPoolId\n });\n return true;\n } catch {\n // User does not exist\n return false;\n }\n }\n\n async createUser(params: {\n username: string;\n temporaryPassword: string;\n attributes: ServiceAbstraction.UserAttributes;\n }): Promise<void> {\n const createUserParams: AdminCreateUserRequest = {\n UserPoolId: this.config.userPoolId,\n Username: params.username,\n DesiredDeliveryMediums: [],\n ForceAliasCreation: false,\n MessageAction: \"SUPPRESS\",\n TemporaryPassword: params.temporaryPassword,\n UserAttributes: [\n {\n Name: \"given_name\",\n Value: params.attributes.givenName || \"\"\n },\n {\n Name: \"family_name\",\n Value: params.attributes.familyName || \"\"\n },\n {\n Name: \"preferred_username\",\n Value: params.attributes.preferredUsername\n },\n {\n Name: \"email\",\n Value: params.attributes.email\n },\n {\n Name: \"custom:id\",\n Value: params.attributes.customId\n }\n ]\n };\n\n await this.cognito.adminCreateUser(createUserParams);\n }\n\n async setEmailVerified(username: string): Promise<void> {\n await this.cognito.adminUpdateUserAttributes({\n UserPoolId: this.config.userPoolId,\n Username: username,\n UserAttributes: [\n {\n Name: \"email_verified\",\n Value: \"true\"\n }\n ]\n });\n }\n\n async setPermanentPassword(username: string, password: string): Promise<void> {\n await this.cognito.adminSetUserPassword({\n Permanent: true,\n Password: password,\n Username: username,\n UserPoolId: this.config.userPoolId\n });\n }\n\n async updateUserAttributes(\n username: string,\n attributes: Record<string, string>\n ): Promise<void> {\n const userAttributes = Object.entries(attributes).map(([name, value]) => ({\n Name: name,\n Value: value\n }));\n\n await this.cognito.adminUpdateUserAttributes({\n UserPoolId: this.config.userPoolId,\n Username: username,\n UserAttributes: userAttributes\n });\n }\n\n async deleteUser(username: string): Promise<void> {\n await this.cognito.adminDeleteUser({\n UserPoolId: this.config.userPoolId,\n Username: username\n });\n }\n}\n\nexport const CognitoService = ServiceAbstraction.createImplementation({\n implementation: CognitoServiceImpl,\n dependencies: [CognitoConfig]\n});\n"],"names":["CognitoServiceImpl","config","CognitoIdentityProvider","username","params","createUserParams","password","attributes","userAttributes","Object","name","value","CognitoService","ServiceAbstraction","CognitoConfig"],"mappings":";;AAIA,MAAMA;IAGF,YAAoBC,MAA+B,CAAE;aAAjCA,MAAM,GAANA;QAChB,IAAI,CAAC,OAAO,GAAG,IAAIC,wBAAwB;YAAE,QAAQD,OAAO,MAAM;QAAC;IACvE;IAEA,MAAM,WAAWE,QAAgB,EAAoB;QACjD,IAAI;YACA,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;gBAC5B,UAAUA;gBACV,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YACtC;YACA,OAAO;QACX,EAAE,OAAM;YAEJ,OAAO;QACX;IACJ;IAEA,MAAM,WAAWC,MAIhB,EAAiB;QACd,MAAMC,mBAA2C;YAC7C,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUD,OAAO,QAAQ;YACzB,wBAAwB,EAAE;YAC1B,oBAAoB;YACpB,eAAe;YACf,mBAAmBA,OAAO,iBAAiB;YAC3C,gBAAgB;gBACZ;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,SAAS,IAAI;gBAC1C;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,UAAU,IAAI;gBAC3C;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,iBAAiB;gBAC9C;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,KAAK;gBAClC;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,QAAQ;gBACrC;aACH;QACL;QAEA,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAACC;IACvC;IAEA,MAAM,iBAAiBF,QAAgB,EAAiB;QACpD,MAAM,IAAI,CAAC,OAAO,CAAC,yBAAyB,CAAC;YACzC,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUA;YACV,gBAAgB;gBACZ;oBACI,MAAM;oBACN,OAAO;gBACX;aACH;QACL;IACJ;IAEA,MAAM,qBAAqBA,QAAgB,EAAEG,QAAgB,EAAiB;QAC1E,MAAM,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC;YACpC,WAAW;YACX,UAAUA;YACV,UAAUH;YACV,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;QACtC;IACJ;IAEA,MAAM,qBACFA,QAAgB,EAChBI,UAAkC,EACrB;QACb,MAAMC,iBAAiBC,OAAO,OAAO,CAACF,YAAY,GAAG,CAAC,CAAC,CAACG,MAAMC,MAAM,GAAM;gBACtE,MAAMD;gBACN,OAAOC;YACX;QAEA,MAAM,IAAI,CAAC,OAAO,CAAC,yBAAyB,CAAC;YACzC,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUR;YACV,gBAAgBK;QACpB;IACJ;IAEA,MAAM,WAAWL,QAAgB,EAAiB;QAC9C,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC;YAC/B,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUA;QACd;IACJ;AACJ;AAEO,MAAMS,gCAAiBC,eAAAA,oBAAuC,CAAC;IAClE,gBAAgBb;IAChB,cAAc;QAACc;KAAc;AACjC"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export const CognitoService = createAbstraction("CognitoService");
|
|
2
|
+
const CognitoConfig = createAbstraction("CognitoConfig");
|
|
3
|
+
const CognitoService = createAbstraction("CognitoService");
|
|
4
|
+
export { CognitoConfig, CognitoService };
|
|
7
5
|
|
|
8
6
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"api/features/CognitoService/abstractions.js","sources":["../../../../src/api/features/CognitoService/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { BaseUserAttributes } from \"@webiny/api-core/types/users.js\";\n\nexport interface AttributeGetter {\n (user: BaseUserAttributes): string;\n}\n\nexport interface ICognitoConfig {\n region: string;\n userPoolId: string;\n}\n\nexport const CognitoConfig = createAbstraction<ICognitoConfig>(\"CognitoConfig\");\n\nexport namespace CognitoConfig {\n export type Interface = ICognitoConfig;\n}\n\n// Cognito Service\n\nexport interface CognitoUserAttributes {\n givenName?: string;\n familyName?: string;\n preferredUsername: string;\n email: string;\n customId: string;\n}\n\nexport interface ICognitoService {\n /**\n * Check if a user exists in Cognito User Pool\n */\n userExists(username: string): Promise<boolean>;\n\n /**\n * Create a new user in Cognito User Pool\n */\n createUser(params: {\n username: string;\n temporaryPassword: string;\n attributes: CognitoUserAttributes;\n }): Promise<void>;\n\n /**\n * Set email as verified for a user\n */\n setEmailVerified(username: string): Promise<void>;\n\n /**\n * Set a permanent password for a user\n */\n setPermanentPassword(username: string, password: string): Promise<void>;\n\n /**\n * Update user attributes in Cognito\n */\n updateUserAttributes(username: string, attributes: Record<string, string>): Promise<void>;\n\n /**\n * Delete a user from Cognito User Pool\n */\n deleteUser(username: string): Promise<void>;\n}\n\nexport const CognitoService = createAbstraction<ICognitoService>(\"CognitoService\");\nexport namespace CognitoService {\n export type Interface = ICognitoService;\n export type UserAttributes = CognitoUserAttributes;\n}\n"],"names":["CognitoConfig","createAbstraction","CognitoService"],"mappings":";AAYO,MAAMA,gBAAgBC,kBAAkC;AAoDxD,MAAMC,iBAAiBD,kBAAmC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { CognitoService } from "./CognitoService.js";
|
|
3
3
|
import { CognitoConfig } from "./abstractions.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const CognitoServiceFeature = createFeature({
|
|
5
|
+
name: "cognitoService",
|
|
6
|
+
register (container, config) {
|
|
7
|
+
container.register(CognitoService).inSingletonScope();
|
|
8
|
+
container.registerInstance(CognitoConfig, config);
|
|
9
|
+
}
|
|
10
10
|
});
|
|
11
|
+
export { CognitoServiceFeature };
|
|
11
12
|
|
|
12
13
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"api/features/CognitoService/feature.js","sources":["../../../../src/api/features/CognitoService/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CognitoService } from \"./CognitoService.js\";\nimport { CognitoConfig } from \"./abstractions.js\";\n\nexport type UserPoolConfig = {\n region: string;\n userPoolId: string;\n};\n\nexport const CognitoServiceFeature = createFeature<UserPoolConfig>({\n name: \"cognitoService\",\n register(container, config) {\n container.register(CognitoService).inSingletonScope();\n\n container.registerInstance(CognitoConfig, config);\n }\n});\n"],"names":["CognitoServiceFeature","createFeature","container","config","CognitoService","CognitoConfig"],"mappings":";;;AASO,MAAMA,wBAAwBC,cAA8B;IAC/D,MAAM;IACN,UAASC,SAAS,EAAEC,MAAM;QACtBD,UAAU,QAAQ,CAACE,gBAAgB,gBAAgB;QAEnDF,UAAU,gBAAgB,CAACG,eAAeF;IAC9C;AACJ"}
|