quidproquo-actionprocessor-awslambda 0.0.87 → 0.0.88
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/getUserDirectoryAuthenticateUserActionProcessor.js +1 -1
- package/lib/getActionProcessor/core/userDirectory/getUserDirectoryCreateUserActionProcessor.js +3 -2
- package/lib/logic/cognito/authenticateUser.d.ts +2 -2
- package/lib/logic/cognito/authenticateUser.js +4 -5
- package/lib/logic/cognito/createUser.d.ts +2 -2
- package/lib/logic/cognito/createUser.js +12 -12
- package/lib/logic/cognito/requestEmailVerificationCode.d.ts +1 -0
- package/lib/logic/cognito/requestEmailVerificationCode.js +23 -0
- package/lib/logic/cognito/setUserPassword.d.ts +1 -0
- package/lib/logic/cognito/setUserPassword.js +25 -0
- package/lib/logic/cognito/verifyUserEmail.d.ts +1 -0
- package/lib/logic/cognito/verifyUserEmail.js +23 -0
- package/package.json +1 -1
package/lib/getActionProcessor/core/userDirectory/getUserDirectoryAuthenticateUserActionProcessor.js
CHANGED
|
@@ -18,7 +18,7 @@ const getUserDirectoryAuthenticateUserActionProcessor = (qpqConfig) => {
|
|
|
18
18
|
const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
|
|
19
19
|
const userPoolId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolIdFromConfig)(payload.userDirectoryName, qpqConfig), region);
|
|
20
20
|
const userPoolClientId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolClientIdFromConfig)(payload.userDirectoryName, qpqConfig), region);
|
|
21
|
-
const authResponse = yield (0, authenticateUser_1.authenticateUser)(userPoolId, userPoolClientId, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig), payload.authenticateUserRequest);
|
|
21
|
+
const authResponse = yield (0, authenticateUser_1.authenticateUser)(userPoolId, userPoolClientId, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig), payload.authenticateUserRequest.email, payload.authenticateUserRequest.password);
|
|
22
22
|
return (0, quidproquo_core_1.actionResult)(authResponse);
|
|
23
23
|
});
|
|
24
24
|
};
|
package/lib/getActionProcessor/core/userDirectory/getUserDirectoryCreateUserActionProcessor.js
CHANGED
|
@@ -17,8 +17,9 @@ const getUserDirectoryCreateUserActionProcessor = (qpqConfig) => {
|
|
|
17
17
|
return (payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
18
|
const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
|
|
19
19
|
const userPoolId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolIdFromConfig)(payload.userDirectoryName, qpqConfig), region);
|
|
20
|
-
const
|
|
21
|
-
|
|
20
|
+
const userPoolClientId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolClientIdFromConfig)(payload.userDirectoryName, qpqConfig), region);
|
|
21
|
+
const authResponse = yield (0, createUser_1.createUser)(userPoolId, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig), userPoolClientId, payload.createUserRequest);
|
|
22
|
+
return (0, quidproquo_core_1.actionResult)(authResponse);
|
|
22
23
|
});
|
|
23
24
|
};
|
|
24
25
|
exports.default = (qpqConfig) => {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const authenticateUser: (userPoolId: string, clientId: string, region: string,
|
|
1
|
+
import { AuthenticateUserResponse } from 'quidproquo-core';
|
|
2
|
+
export declare const authenticateUser: (userPoolId: string, clientId: string, region: string, username: string, password: string) => Promise<AuthenticateUserResponse>;
|
|
@@ -21,22 +21,21 @@ const cognitoAuthenticationResultTypeToQpqAuthenticationInfo = (authResult) => (
|
|
|
21
21
|
refreshToken: authResult.RefreshToken,
|
|
22
22
|
tokenType: authResult.TokenType,
|
|
23
23
|
});
|
|
24
|
-
const authenticateUser = (userPoolId, clientId, region,
|
|
24
|
+
const authenticateUser = (userPoolId, clientId, region, username, password) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
25
|
const cognitoClient = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({ region });
|
|
26
26
|
const clientSecret = yield (0, getUserPoolClientSecret_1.getUserPoolClientSecret)(userPoolId, clientId, region);
|
|
27
|
-
const secretHash = (0, calculateSecretHash_1.calculateSecretHash)(
|
|
27
|
+
const secretHash = (0, calculateSecretHash_1.calculateSecretHash)(username, clientId, clientSecret);
|
|
28
28
|
const params = {
|
|
29
29
|
AuthFlow: client_cognito_identity_provider_1.AuthFlowType.ADMIN_USER_PASSWORD_AUTH,
|
|
30
30
|
UserPoolId: userPoolId,
|
|
31
31
|
ClientId: clientId,
|
|
32
32
|
AuthParameters: {
|
|
33
|
-
USERNAME:
|
|
34
|
-
PASSWORD:
|
|
33
|
+
USERNAME: username,
|
|
34
|
+
PASSWORD: password,
|
|
35
35
|
SECRET_HASH: secretHash,
|
|
36
36
|
},
|
|
37
37
|
};
|
|
38
38
|
const response = yield cognitoClient.send(new client_cognito_identity_provider_1.AdminInitiateAuthCommand(params));
|
|
39
|
-
console.log(JSON.stringify(response, null, 2));
|
|
40
39
|
const authenticateUserResponse = {
|
|
41
40
|
session: response.Session,
|
|
42
41
|
challenge: quidproquo_core_1.AuthenticateUserChallenge.NONE,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CreateUserRequest } from 'quidproquo-core';
|
|
2
|
-
export declare const createUser: (userPoolId: string, region: string, createUserRequest: CreateUserRequest) => Promise<
|
|
1
|
+
import { CreateUserRequest, AuthenticateUserResponse } from 'quidproquo-core';
|
|
2
|
+
export declare const createUser: (userPoolId: string, region: string, clientId: string, createUserRequest: CreateUserRequest) => Promise<AuthenticateUserResponse>;
|
|
@@ -11,7 +11,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createUser = void 0;
|
|
13
13
|
const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
|
|
14
|
-
const
|
|
14
|
+
const authenticateUser_1 = require("./authenticateUser");
|
|
15
|
+
const setUserPassword_1 = require("./setUserPassword");
|
|
16
|
+
const createUser = (userPoolId, region, clientId, createUserRequest) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
17
|
var _a;
|
|
16
18
|
const cognitoClient = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({ region });
|
|
17
19
|
const params = {
|
|
@@ -19,7 +21,10 @@ const createUser = (userPoolId, region, createUserRequest) => __awaiter(void 0,
|
|
|
19
21
|
Username: createUserRequest.email,
|
|
20
22
|
MessageAction: client_cognito_identity_provider_1.MessageActionType.SUPPRESS,
|
|
21
23
|
DesiredDeliveryMediums: [client_cognito_identity_provider_1.DeliveryMediumType.EMAIL],
|
|
22
|
-
UserAttributes: [
|
|
24
|
+
UserAttributes: [
|
|
25
|
+
{ Name: 'email', Value: createUserRequest.email },
|
|
26
|
+
{ Name: 'email_verified', Value: 'false' },
|
|
27
|
+
],
|
|
23
28
|
ForceAliasCreation: false,
|
|
24
29
|
};
|
|
25
30
|
if (createUserRequest.phone) {
|
|
@@ -28,15 +33,10 @@ const createUser = (userPoolId, region, createUserRequest) => __awaiter(void 0,
|
|
|
28
33
|
}
|
|
29
34
|
const response = yield cognitoClient.send(new client_cognito_identity_provider_1.AdminCreateUserCommand(params));
|
|
30
35
|
const username = ((_a = response.User) === null || _a === void 0 ? void 0 : _a.Username) || '';
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Permanent: true,
|
|
37
|
-
};
|
|
38
|
-
yield cognitoClient.send(new client_cognito_identity_provider_1.AdminSetUserPasswordCommand(passwordParams));
|
|
39
|
-
// ///////////////////////
|
|
40
|
-
return username;
|
|
36
|
+
// Set the user's password
|
|
37
|
+
yield (0, setUserPassword_1.setUserPassword)(region, userPoolId, username, createUserRequest.password);
|
|
38
|
+
// Authenticate the user
|
|
39
|
+
const authResponse = yield (0, authenticateUser_1.authenticateUser)(userPoolId, clientId, region, username, createUserRequest.password);
|
|
40
|
+
return authResponse;
|
|
41
41
|
});
|
|
42
42
|
exports.createUser = createUser;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const requestEmailVerificationCode: (region: string, accessToken: string) => Promise<void>;
|
|
@@ -0,0 +1,23 @@
|
|
|
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.requestEmailVerificationCode = void 0;
|
|
13
|
+
const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
|
|
14
|
+
const requestEmailVerificationCode = (region, accessToken) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const cognitoClient = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({ region });
|
|
16
|
+
const params = {
|
|
17
|
+
AccessToken: accessToken,
|
|
18
|
+
AttributeName: 'email', // Request verification for the email attribute
|
|
19
|
+
};
|
|
20
|
+
const requestEmailVerificationCodeResponse = yield cognitoClient.send(new client_cognito_identity_provider_1.GetUserAttributeVerificationCodeCommand(params));
|
|
21
|
+
console.log(JSON.stringify(requestEmailVerificationCodeResponse, null, 2));
|
|
22
|
+
});
|
|
23
|
+
exports.requestEmailVerificationCode = requestEmailVerificationCode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const setUserPassword: (region: string, userPoolId: string, username: string, password: string) => Promise<void>;
|
|
@@ -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
|
+
exports.setUserPassword = void 0;
|
|
13
|
+
const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
|
|
14
|
+
const setUserPassword = (region, userPoolId, username, password) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const cognitoClient = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({ region });
|
|
16
|
+
// There has to be a better way than this?
|
|
17
|
+
const passwordParams = {
|
|
18
|
+
Password: password,
|
|
19
|
+
Username: username,
|
|
20
|
+
UserPoolId: userPoolId,
|
|
21
|
+
Permanent: true,
|
|
22
|
+
};
|
|
23
|
+
yield cognitoClient.send(new client_cognito_identity_provider_1.AdminSetUserPasswordCommand(passwordParams));
|
|
24
|
+
});
|
|
25
|
+
exports.setUserPassword = setUserPassword;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const verifyUserEmail: (region: string, accessToken: string, verificationCode: string) => Promise<void>;
|
|
@@ -0,0 +1,23 @@
|
|
|
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.verifyUserEmail = void 0;
|
|
13
|
+
const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
|
|
14
|
+
const verifyUserEmail = (region, accessToken, verificationCode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const cognitoClient = new client_cognito_identity_provider_1.CognitoIdentityProviderClient({ region });
|
|
16
|
+
const params = {
|
|
17
|
+
AccessToken: accessToken,
|
|
18
|
+
AttributeName: 'email',
|
|
19
|
+
Code: verificationCode,
|
|
20
|
+
};
|
|
21
|
+
yield cognitoClient.send(new client_cognito_identity_provider_1.VerifyUserAttributeCommand(params));
|
|
22
|
+
});
|
|
23
|
+
exports.verifyUserEmail = verifyUserEmail;
|