quidproquo-actionprocessor-awslambda 0.0.88 → 0.0.89
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/lib/getActionProcessor/core/userDirectory/getUserDirectoryConfirmEmailVerificationActionProcessor.d.ts +5 -0
- package/lib/getActionProcessor/core/userDirectory/getUserDirectoryConfirmEmailVerificationActionProcessor.js +25 -0
- package/lib/getActionProcessor/core/userDirectory/getUserDirectoryConfirmForgetPasswordActionProcessor.d.ts +5 -0
- package/lib/getActionProcessor/core/userDirectory/getUserDirectoryConfirmForgetPasswordActionProcessor.js +29 -0
- package/lib/getActionProcessor/core/userDirectory/getUserDirectoryForgetPasswordActionProcessor.d.ts +5 -0
- package/lib/getActionProcessor/core/userDirectory/getUserDirectoryForgetPasswordActionProcessor.js +29 -0
- package/lib/getActionProcessor/core/userDirectory/getUserDirectoryRefreshTokenActionProcessor.d.ts +5 -0
- package/lib/getActionProcessor/core/userDirectory/getUserDirectoryRefreshTokenActionProcessor.js +29 -0
- package/lib/getActionProcessor/core/userDirectory/getUserDirectoryRequestEmailVerificationActionProcessor.d.ts +5 -0
- package/lib/getActionProcessor/core/userDirectory/getUserDirectoryRequestEmailVerificationActionProcessor.js +25 -0
- package/lib/getActionProcessor/core/userDirectory/index.d.ts +5 -0
- package/lib/getActionProcessor/core/userDirectory/index.js +6 -1
- package/lib/logic/cognito/authenticateUser.js +18 -16
- package/lib/logic/cognito/confirmForgotPassword.d.ts +2 -0
- package/lib/logic/cognito/confirmForgotPassword.js +33 -0
- package/lib/logic/cognito/createUser.d.ts +4 -0
- package/lib/logic/cognito/createUser.js +32 -7
- package/lib/logic/cognito/forgotPassword.d.ts +2 -0
- package/lib/logic/cognito/forgotPassword.js +33 -0
- package/lib/logic/cognito/refreshToken.d.ts +2 -0
- package/lib/logic/cognito/refreshToken.js +33 -0
- package/lib/logic/cognito/utils/transformCognitoResponse.d.ts +4 -0
- package/lib/logic/cognito/utils/transformCognitoResponse.js +23 -0
- package/package.json +1 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { UserDirectoryConfirmEmailVerificationActionProcessor, QPQConfig } from 'quidproquo-core';
|
|
2
|
+
declare const _default: (qpqConfig: QPQConfig) => {
|
|
3
|
+
"@quidproquo-core/UserDirectory/ConfirmEmailVerification": UserDirectoryConfirmEmailVerificationActionProcessor;
|
|
4
|
+
};
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
13
|
+
const verifyUserEmail_1 = require("../../../logic/cognito/verifyUserEmail");
|
|
14
|
+
const getUserDirectoryConfirmEmailVerificationActionProcessor = (qpqConfig) => {
|
|
15
|
+
return ({ code, accessToken }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
|
|
17
|
+
yield (0, verifyUserEmail_1.verifyUserEmail)(region, accessToken, code);
|
|
18
|
+
return (0, quidproquo_core_1.actionResult)(void 0);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.default = (qpqConfig) => {
|
|
22
|
+
return {
|
|
23
|
+
[quidproquo_core_1.UserDirectoryActionType.ConfirmEmailVerification]: getUserDirectoryConfirmEmailVerificationActionProcessor(qpqConfig),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { UserDirectoryConfirmForgotPasswordActionProcessor, QPQConfig } from 'quidproquo-core';
|
|
2
|
+
declare const _default: (qpqConfig: QPQConfig) => {
|
|
3
|
+
"@quidproquo-core/UserDirectory/ConfirmForgotPassword": UserDirectoryConfirmForgotPasswordActionProcessor;
|
|
4
|
+
};
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
13
|
+
const awsNamingUtils_1 = require("../../../awsNamingUtils");
|
|
14
|
+
const confirmForgotPassword_1 = require("../../../logic/cognito/confirmForgotPassword");
|
|
15
|
+
const getExportedValue_1 = require("../../../logic/cloudformation/getExportedValue");
|
|
16
|
+
const getUserDirectoryConfirmForgotPasswordActionProcessor = (qpqConfig) => {
|
|
17
|
+
return ({ userDirectoryName, code, username, password }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
|
|
19
|
+
const userPoolId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolIdFromConfig)(userDirectoryName, qpqConfig), region);
|
|
20
|
+
const userPoolClientId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolClientIdFromConfig)(userDirectoryName, qpqConfig), region);
|
|
21
|
+
const authResponse = yield (0, confirmForgotPassword_1.confirmForgotPassword)(userPoolId, userPoolClientId, region, code, username, password);
|
|
22
|
+
return (0, quidproquo_core_1.actionResult)(authResponse);
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.default = (qpqConfig) => {
|
|
26
|
+
return {
|
|
27
|
+
[quidproquo_core_1.UserDirectoryActionType.ConfirmForgotPassword]: getUserDirectoryConfirmForgotPasswordActionProcessor(qpqConfig),
|
|
28
|
+
};
|
|
29
|
+
};
|
package/lib/getActionProcessor/core/userDirectory/getUserDirectoryForgetPasswordActionProcessor.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
13
|
+
const awsNamingUtils_1 = require("../../../awsNamingUtils");
|
|
14
|
+
const forgotPassword_1 = require("../../../logic/cognito/forgotPassword");
|
|
15
|
+
const getExportedValue_1 = require("../../../logic/cloudformation/getExportedValue");
|
|
16
|
+
const getUserDirectoryForgotPasswordActionProcessor = (qpqConfig) => {
|
|
17
|
+
return ({ username, userDirectoryName }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
|
|
19
|
+
const userPoolId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolIdFromConfig)(userDirectoryName, qpqConfig), region);
|
|
20
|
+
const userPoolClientId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolClientIdFromConfig)(userDirectoryName, qpqConfig), region);
|
|
21
|
+
const authResponse = yield (0, forgotPassword_1.forgotPassword)(userPoolId, userPoolClientId, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig), username);
|
|
22
|
+
return (0, quidproquo_core_1.actionResult)(authResponse);
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.default = (qpqConfig) => {
|
|
26
|
+
return {
|
|
27
|
+
[quidproquo_core_1.UserDirectoryActionType.ForgotPassword]: getUserDirectoryForgotPasswordActionProcessor(qpqConfig),
|
|
28
|
+
};
|
|
29
|
+
};
|
package/lib/getActionProcessor/core/userDirectory/getUserDirectoryRefreshTokenActionProcessor.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
13
|
+
const awsNamingUtils_1 = require("../../../awsNamingUtils");
|
|
14
|
+
const refreshToken_1 = require("../../../logic/cognito/refreshToken");
|
|
15
|
+
const getExportedValue_1 = require("../../../logic/cloudformation/getExportedValue");
|
|
16
|
+
const getUserDirectoryRefreshTokenActionProcessor = (qpqConfig) => {
|
|
17
|
+
return ({ userDirectoryName, username, refreshToken }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
|
|
19
|
+
const userPoolId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolIdFromConfig)(userDirectoryName, qpqConfig), region);
|
|
20
|
+
const userPoolClientId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolClientIdFromConfig)(userDirectoryName, qpqConfig), region);
|
|
21
|
+
const authResponse = yield (0, refreshToken_1.refreshToken)(userPoolId, userPoolClientId, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig), username, refreshToken);
|
|
22
|
+
return (0, quidproquo_core_1.actionResult)(authResponse);
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.default = (qpqConfig) => {
|
|
26
|
+
return {
|
|
27
|
+
[quidproquo_core_1.UserDirectoryActionType.RefreshToken]: getUserDirectoryRefreshTokenActionProcessor(qpqConfig),
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { UserDirectoryRequestEmailVerificationActionProcessor, QPQConfig } from 'quidproquo-core';
|
|
2
|
+
declare const _default: (qpqConfig: QPQConfig) => {
|
|
3
|
+
"@quidproquo-core/UserDirectory/RequestEmailVerification": UserDirectoryRequestEmailVerificationActionProcessor;
|
|
4
|
+
};
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
13
|
+
const requestEmailVerificationCode_1 = require("../../../logic/cognito/requestEmailVerificationCode");
|
|
14
|
+
const getUserDirectoryRequestEmailVerificationActionProcessor = (qpqConfig) => {
|
|
15
|
+
return ({ userDirectoryName, accessToken }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
|
|
17
|
+
yield (0, requestEmailVerificationCode_1.requestEmailVerificationCode)(region, accessToken);
|
|
18
|
+
return (0, quidproquo_core_1.actionResult)(void 0);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.default = (qpqConfig) => {
|
|
22
|
+
return {
|
|
23
|
+
[quidproquo_core_1.UserDirectoryActionType.RequestEmailVerification]: getUserDirectoryRequestEmailVerificationActionProcessor(qpqConfig),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { QPQConfig } from 'quidproquo-core';
|
|
2
2
|
declare const _default: (qpqConfig: QPQConfig) => {
|
|
3
|
+
"@quidproquo-core/UserDirectory/RequestEmailVerification": import("quidproquo-core").UserDirectoryRequestEmailVerificationActionProcessor;
|
|
4
|
+
"@quidproquo-core/UserDirectory/RefreshToken": import("quidproquo-core").UserDirectoryRefreshTokenActionProcessor;
|
|
5
|
+
"@quidproquo-core/UserDirectory/ForgotPassword": import("quidproquo-core").UserDirectoryForgotPasswordActionProcessor;
|
|
3
6
|
"@quidproquo-core/UserDirectory/CreateUser": import("quidproquo-core").UserDirectoryCreateUserActionProcessor;
|
|
7
|
+
"@quidproquo-core/UserDirectory/ConfirmForgotPassword": import("quidproquo-core").UserDirectoryConfirmForgotPasswordActionProcessor;
|
|
8
|
+
"@quidproquo-core/UserDirectory/ConfirmEmailVerification": import("quidproquo-core").UserDirectoryConfirmEmailVerificationActionProcessor;
|
|
4
9
|
"@quidproquo-core/UserDirectory/AuthenticateUser": import("quidproquo-core").UserDirectoryAuthenticateUserActionProcessor;
|
|
5
10
|
};
|
|
6
11
|
export default _default;
|
|
@@ -4,5 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const getUserDirectoryAuthenticateUserActionProcessor_1 = __importDefault(require("./getUserDirectoryAuthenticateUserActionProcessor"));
|
|
7
|
+
const getUserDirectoryConfirmEmailVerificationActionProcessor_1 = __importDefault(require("./getUserDirectoryConfirmEmailVerificationActionProcessor"));
|
|
8
|
+
const getUserDirectoryConfirmForgetPasswordActionProcessor_1 = __importDefault(require("./getUserDirectoryConfirmForgetPasswordActionProcessor"));
|
|
7
9
|
const getUserDirectoryCreateUserActionProcessor_1 = __importDefault(require("./getUserDirectoryCreateUserActionProcessor"));
|
|
8
|
-
|
|
10
|
+
const getUserDirectoryForgetPasswordActionProcessor_1 = __importDefault(require("./getUserDirectoryForgetPasswordActionProcessor"));
|
|
11
|
+
const getUserDirectoryRefreshTokenActionProcessor_1 = __importDefault(require("./getUserDirectoryRefreshTokenActionProcessor"));
|
|
12
|
+
const getUserDirectoryRequestEmailVerificationActionProcessor_1 = __importDefault(require("./getUserDirectoryRequestEmailVerificationActionProcessor"));
|
|
13
|
+
exports.default = (qpqConfig) => (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (0, getUserDirectoryAuthenticateUserActionProcessor_1.default)(qpqConfig)), (0, getUserDirectoryConfirmEmailVerificationActionProcessor_1.default)(qpqConfig)), (0, getUserDirectoryConfirmForgetPasswordActionProcessor_1.default)(qpqConfig)), (0, getUserDirectoryCreateUserActionProcessor_1.default)(qpqConfig)), (0, getUserDirectoryForgetPasswordActionProcessor_1.default)(qpqConfig)), (0, getUserDirectoryRefreshTokenActionProcessor_1.default)(qpqConfig)), (0, getUserDirectoryRequestEmailVerificationActionProcessor_1.default)(qpqConfig)));
|
|
@@ -14,13 +14,8 @@ const quidproquo_core_1 = require("quidproquo-core");
|
|
|
14
14
|
const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
|
|
15
15
|
const calculateSecretHash_1 = require("./utils/calculateSecretHash");
|
|
16
16
|
const getUserPoolClientSecret_1 = require("./getUserPoolClientSecret");
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
idToken: authResult.IdToken,
|
|
20
|
-
expiresIn: authResult.ExpiresIn,
|
|
21
|
-
refreshToken: authResult.RefreshToken,
|
|
22
|
-
tokenType: authResult.TokenType,
|
|
23
|
-
});
|
|
17
|
+
const transformCognitoResponse_1 = require("./utils/transformCognitoResponse");
|
|
18
|
+
// TODO: retry for TooManyRequestsException
|
|
24
19
|
const authenticateUser = (userPoolId, clientId, region, username, password) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
20
|
const cognitoClient = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({ region });
|
|
26
21
|
const clientSecret = yield (0, getUserPoolClientSecret_1.getUserPoolClientSecret)(userPoolId, clientId, region);
|
|
@@ -35,15 +30,22 @@ const authenticateUser = (userPoolId, clientId, region, username, password) => _
|
|
|
35
30
|
SECRET_HASH: secretHash,
|
|
36
31
|
},
|
|
37
32
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
try {
|
|
34
|
+
const response = yield cognitoClient.send(new client_cognito_identity_provider_1.AdminInitiateAuthCommand(params));
|
|
35
|
+
return (0, transformCognitoResponse_1.cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo)(response);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
if (e instanceof Error) {
|
|
39
|
+
switch (e.name) {
|
|
40
|
+
case 'PasswordResetRequiredException':
|
|
41
|
+
return {
|
|
42
|
+
challenge: quidproquo_core_1.AuthenticateUserChallenge.RESET_PASSWORD,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`${e.name}: ${e.message}`);
|
|
46
|
+
}
|
|
47
|
+
console.log('authenticateUser Error: ', e);
|
|
48
|
+
throw new Error(`Unknown error has occurred in authenticateUser`);
|
|
46
49
|
}
|
|
47
|
-
return authenticateUserResponse;
|
|
48
50
|
});
|
|
49
51
|
exports.authenticateUser = authenticateUser;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.confirmForgotPassword = void 0;
|
|
13
|
+
const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
|
|
14
|
+
const calculateSecretHash_1 = require("./utils/calculateSecretHash");
|
|
15
|
+
const getUserPoolClientSecret_1 = require("./getUserPoolClientSecret");
|
|
16
|
+
const authenticateUser_1 = require("./authenticateUser");
|
|
17
|
+
const confirmForgotPassword = (userPoolId, clientId, region, code, username, password) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const cognitoClient = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({ region });
|
|
19
|
+
const clientSecret = yield (0, getUserPoolClientSecret_1.getUserPoolClientSecret)(userPoolId, clientId, region);
|
|
20
|
+
const secretHash = (0, calculateSecretHash_1.calculateSecretHash)(username, clientId, clientSecret);
|
|
21
|
+
const params = {
|
|
22
|
+
ClientId: clientId,
|
|
23
|
+
ConfirmationCode: code,
|
|
24
|
+
SecretHash: secretHash,
|
|
25
|
+
Password: password,
|
|
26
|
+
Username: username,
|
|
27
|
+
};
|
|
28
|
+
yield cognitoClient.send(new client_cognito_identity_provider_1.ConfirmForgotPasswordCommand(params));
|
|
29
|
+
// Authenticate the user
|
|
30
|
+
const authResponse = yield (0, authenticateUser_1.authenticateUser)(userPoolId, clientId, region, username, password);
|
|
31
|
+
return authResponse;
|
|
32
|
+
});
|
|
33
|
+
exports.confirmForgotPassword = confirmForgotPassword;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { CreateUserRequest, AuthenticateUserResponse } from 'quidproquo-core';
|
|
2
|
+
export declare const getUserAttributesFromCreateUserRequest: (createUserRequest: CreateUserRequest) => {
|
|
3
|
+
Name: string;
|
|
4
|
+
Value: string;
|
|
5
|
+
}[];
|
|
2
6
|
export declare const createUser: (userPoolId: string, region: string, clientId: string, createUserRequest: CreateUserRequest) => Promise<AuthenticateUserResponse>;
|
|
@@ -9,10 +9,39 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createUser = void 0;
|
|
12
|
+
exports.createUser = exports.getUserAttributesFromCreateUserRequest = void 0;
|
|
13
13
|
const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
|
|
14
14
|
const authenticateUser_1 = require("./authenticateUser");
|
|
15
15
|
const setUserPassword_1 = require("./setUserPassword");
|
|
16
|
+
const cognitoAttributeMap = {
|
|
17
|
+
email: 'email',
|
|
18
|
+
emailVerified: 'email_verified',
|
|
19
|
+
password: 'password',
|
|
20
|
+
address: 'address',
|
|
21
|
+
birthDate: 'birthdate',
|
|
22
|
+
familyName: 'family_name',
|
|
23
|
+
gender: 'gender',
|
|
24
|
+
givenName: 'given_name',
|
|
25
|
+
locale: 'locale',
|
|
26
|
+
middleName: 'middle_name',
|
|
27
|
+
name: 'name',
|
|
28
|
+
nickname: 'nickname',
|
|
29
|
+
phoneNumber: 'phone_number',
|
|
30
|
+
picture: 'picture',
|
|
31
|
+
preferredUsername: 'preferred_username',
|
|
32
|
+
profile: 'profile',
|
|
33
|
+
website: 'website',
|
|
34
|
+
zoneInfo: 'zoneinfo',
|
|
35
|
+
};
|
|
36
|
+
const getUserAttributesFromCreateUserRequest = (createUserRequest) => {
|
|
37
|
+
return Object.keys(createUserRequest)
|
|
38
|
+
.map((key) => ({
|
|
39
|
+
Name: cognitoAttributeMap[key],
|
|
40
|
+
Value: `${createUserRequest[key]}`,
|
|
41
|
+
}))
|
|
42
|
+
.filter((attribute) => !!attribute.Value && attribute.Name !== 'password');
|
|
43
|
+
};
|
|
44
|
+
exports.getUserAttributesFromCreateUserRequest = getUserAttributesFromCreateUserRequest;
|
|
16
45
|
const createUser = (userPoolId, region, clientId, createUserRequest) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
46
|
var _a;
|
|
18
47
|
const cognitoClient = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({ region });
|
|
@@ -21,15 +50,11 @@ const createUser = (userPoolId, region, clientId, createUserRequest) => __awaite
|
|
|
21
50
|
Username: createUserRequest.email,
|
|
22
51
|
MessageAction: client_cognito_identity_provider_1.MessageActionType.SUPPRESS,
|
|
23
52
|
DesiredDeliveryMediums: [client_cognito_identity_provider_1.DeliveryMediumType.EMAIL],
|
|
24
|
-
UserAttributes:
|
|
25
|
-
{ Name: 'email', Value: createUserRequest.email },
|
|
26
|
-
{ Name: 'email_verified', Value: 'false' },
|
|
27
|
-
],
|
|
53
|
+
UserAttributes: (0, exports.getUserAttributesFromCreateUserRequest)(createUserRequest),
|
|
28
54
|
ForceAliasCreation: false,
|
|
29
55
|
};
|
|
30
|
-
if (createUserRequest.
|
|
56
|
+
if (createUserRequest.phoneNumber) {
|
|
31
57
|
params.DesiredDeliveryMediums.push(client_cognito_identity_provider_1.DeliveryMediumType.SMS);
|
|
32
|
-
params.UserAttributes.push({ Name: 'phone_number', Value: createUserRequest.phone });
|
|
33
58
|
}
|
|
34
59
|
const response = yield cognitoClient.send(new client_cognito_identity_provider_1.AdminCreateUserCommand(params));
|
|
35
60
|
const username = ((_a = response.User) === null || _a === void 0 ? void 0 : _a.Username) || '';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.forgotPassword = void 0;
|
|
13
|
+
const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
|
|
14
|
+
const calculateSecretHash_1 = require("./utils/calculateSecretHash");
|
|
15
|
+
const getUserPoolClientSecret_1 = require("./getUserPoolClientSecret");
|
|
16
|
+
const forgotPassword = (userPoolId, clientId, region, username) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const cognitoClient = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({ region });
|
|
18
|
+
const clientSecret = yield (0, getUserPoolClientSecret_1.getUserPoolClientSecret)(userPoolId, clientId, region);
|
|
19
|
+
const secretHash = (0, calculateSecretHash_1.calculateSecretHash)(username, clientId, clientSecret);
|
|
20
|
+
const params = {
|
|
21
|
+
ClientId: clientId,
|
|
22
|
+
Username: username,
|
|
23
|
+
SecretHash: secretHash,
|
|
24
|
+
};
|
|
25
|
+
const response = yield cognitoClient.send(new client_cognito_identity_provider_1.ForgotPasswordCommand(params));
|
|
26
|
+
const deliveryInfo = {
|
|
27
|
+
attributeName: response.CodeDeliveryDetails.AttributeName || 'email',
|
|
28
|
+
destination: response.CodeDeliveryDetails.Destination || 'unknown@email.com',
|
|
29
|
+
deliveryMedium: response.CodeDeliveryDetails.DeliveryMedium || 'EMAIL',
|
|
30
|
+
};
|
|
31
|
+
return deliveryInfo;
|
|
32
|
+
});
|
|
33
|
+
exports.forgotPassword = forgotPassword;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.refreshToken = void 0;
|
|
13
|
+
const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
|
|
14
|
+
const calculateSecretHash_1 = require("./utils/calculateSecretHash");
|
|
15
|
+
const getUserPoolClientSecret_1 = require("./getUserPoolClientSecret");
|
|
16
|
+
const transformCognitoResponse_1 = require("./utils/transformCognitoResponse");
|
|
17
|
+
const refreshToken = (userPoolId, clientId, region, username, refreshToken) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const cognitoClient = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({ region });
|
|
19
|
+
const clientSecret = yield (0, getUserPoolClientSecret_1.getUserPoolClientSecret)(userPoolId, clientId, region);
|
|
20
|
+
const secretHash = (0, calculateSecretHash_1.calculateSecretHash)(username, clientId, clientSecret);
|
|
21
|
+
const params = {
|
|
22
|
+
AuthFlow: client_cognito_identity_provider_1.AuthFlowType.REFRESH_TOKEN_AUTH,
|
|
23
|
+
UserPoolId: userPoolId,
|
|
24
|
+
ClientId: clientId,
|
|
25
|
+
AuthParameters: {
|
|
26
|
+
REFRESH_TOKEN: refreshToken,
|
|
27
|
+
SECRET_HASH: secretHash,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const response = yield cognitoClient.send(new client_cognito_identity_provider_1.AdminInitiateAuthCommand(params));
|
|
31
|
+
return (0, transformCognitoResponse_1.cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo)(response);
|
|
32
|
+
});
|
|
33
|
+
exports.refreshToken = refreshToken;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AuthenticateUserResponse, AuthenticationInfo } from 'quidproquo-core';
|
|
2
|
+
import { AuthenticationResultType, AdminInitiateAuthResponse } from '@aws-sdk/client-cognito-identity-provider';
|
|
3
|
+
export declare const cognitoAuthenticationResultTypeToQpqAuthenticationInfo: (authResult: AuthenticationResultType) => AuthenticationInfo;
|
|
4
|
+
export declare const cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo: (authResponse: AdminInitiateAuthResponse) => AuthenticateUserResponse;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo = exports.cognitoAuthenticationResultTypeToQpqAuthenticationInfo = void 0;
|
|
4
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
5
|
+
const cognitoAuthenticationResultTypeToQpqAuthenticationInfo = (authResult) => ({
|
|
6
|
+
accessToken: authResult.AccessToken,
|
|
7
|
+
idToken: authResult.IdToken,
|
|
8
|
+
expiresIn: authResult.ExpiresIn,
|
|
9
|
+
refreshToken: authResult.RefreshToken,
|
|
10
|
+
tokenType: authResult.TokenType,
|
|
11
|
+
});
|
|
12
|
+
exports.cognitoAuthenticationResultTypeToQpqAuthenticationInfo = cognitoAuthenticationResultTypeToQpqAuthenticationInfo;
|
|
13
|
+
const cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo = (authResponse) => {
|
|
14
|
+
const res = {
|
|
15
|
+
session: authResponse.Session,
|
|
16
|
+
challenge: quidproquo_core_1.AuthenticateUserChallenge.NONE,
|
|
17
|
+
};
|
|
18
|
+
if (authResponse.AuthenticationResult) {
|
|
19
|
+
res.authenticationInfo = (0, exports.cognitoAuthenticationResultTypeToQpqAuthenticationInfo)(authResponse.AuthenticationResult);
|
|
20
|
+
}
|
|
21
|
+
return res;
|
|
22
|
+
};
|
|
23
|
+
exports.cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo = cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo;
|