quidproquo-actionprocessor-awslambda 0.0.98 → 0.0.99
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/getUserDirectoryRespondToAuthChallengeActionProcessor.d.ts +5 -0
- package/lib/getActionProcessor/core/userDirectory/getUserDirectoryRespondToAuthChallengeActionProcessor.js +39 -0
- package/lib/getActionProcessor/core/userDirectory/index.d.ts +1 -0
- package/lib/getActionProcessor/core/userDirectory/index.js +2 -1
- package/lib/logic/cognito/authenticateUser.js +1 -0
- package/lib/logic/cognito/respondToAuthChallengeChallenge.d.ts +2 -0
- package/lib/logic/cognito/respondToAuthChallengeChallenge.js +33 -0
- package/lib/logic/cognito/utils/transformCognitoResponse.d.ts +3 -2
- package/lib/logic/cognito/utils/transformCognitoResponse.js +15 -2
- package/package.json +1 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { UserDirectoryRespondToAuthChallengeActionProcessor, QPQConfig } from 'quidproquo-core';
|
|
2
|
+
declare const _default: (qpqConfig: QPQConfig) => {
|
|
3
|
+
"@quidproquo-core/UserDirectory/RespondToAuthChallenge": UserDirectoryRespondToAuthChallengeActionProcessor;
|
|
4
|
+
};
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,39 @@
|
|
|
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 getExportedValue_1 = require("../../../logic/cloudformation/getExportedValue");
|
|
15
|
+
const respondToAuthChallengeChallenge_1 = require("../../../logic/cognito/respondToAuthChallengeChallenge");
|
|
16
|
+
const anyAuthChallengeToCognitoAttributes = (authChallenge) => {
|
|
17
|
+
switch (authChallenge.challenge) {
|
|
18
|
+
case quidproquo_core_1.AuthenticateUserChallenge.NEW_PASSWORD_REQUIRED:
|
|
19
|
+
return {
|
|
20
|
+
NEW_PASSWORD: authChallenge.newPassword,
|
|
21
|
+
};
|
|
22
|
+
default:
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const getUserDirectoryRespondToAuthChallengeActionProcessor = (qpqConfig) => {
|
|
27
|
+
return ({ userDirectoryName, authChallenge }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
|
|
29
|
+
const userPoolId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolIdFromConfig)(userDirectoryName, qpqConfig), region);
|
|
30
|
+
const userPoolClientId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolClientIdFromConfig)(userDirectoryName, qpqConfig), region);
|
|
31
|
+
const response = yield (0, respondToAuthChallengeChallenge_1.respondToAuthChallengeChallenge)(userPoolId, userPoolClientId, region, authChallenge.username, authChallenge.session, anyAuthChallengeToCognitoAttributes(authChallenge));
|
|
32
|
+
return (0, quidproquo_core_1.actionResult)(response);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
exports.default = (qpqConfig) => {
|
|
36
|
+
return {
|
|
37
|
+
[quidproquo_core_1.UserDirectoryActionType.RespondToAuthChallenge]: getUserDirectoryRespondToAuthChallengeActionProcessor(qpqConfig),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { QPQConfig } from 'quidproquo-core';
|
|
2
2
|
declare const _default: (qpqConfig: QPQConfig) => {
|
|
3
|
+
"@quidproquo-core/UserDirectory/RespondToAuthChallenge": import("quidproquo-core").UserDirectoryRespondToAuthChallengeActionProcessor;
|
|
3
4
|
"@quidproquo-core/UserDirectory/RequestEmailVerification": import("quidproquo-core").UserDirectoryRequestEmailVerificationActionProcessor;
|
|
4
5
|
"@quidproquo-core/UserDirectory/RefreshToken": import("quidproquo-core").UserDirectoryRefreshTokenActionProcessor;
|
|
5
6
|
"@quidproquo-core/UserDirectory/ReadAccessToken": import("quidproquo-core").UserDirectoryReadAccessTokenActionProcessor;
|
|
@@ -11,4 +11,5 @@ const getUserDirectoryForgetPasswordActionProcessor_1 = __importDefault(require(
|
|
|
11
11
|
const getUserDirectoryReadAccessTokenActionProcessor_1 = __importDefault(require("./getUserDirectoryReadAccessTokenActionProcessor"));
|
|
12
12
|
const getUserDirectoryRefreshTokenActionProcessor_1 = __importDefault(require("./getUserDirectoryRefreshTokenActionProcessor"));
|
|
13
13
|
const getUserDirectoryRequestEmailVerificationActionProcessor_1 = __importDefault(require("./getUserDirectoryRequestEmailVerificationActionProcessor"));
|
|
14
|
-
|
|
14
|
+
const getUserDirectoryRespondToAuthChallengeActionProcessor_1 = __importDefault(require("./getUserDirectoryRespondToAuthChallengeActionProcessor"));
|
|
15
|
+
exports.default = (qpqConfig) => (Object.assign(Object.assign(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, getUserDirectoryReadAccessTokenActionProcessor_1.default)(qpqConfig)), (0, getUserDirectoryRefreshTokenActionProcessor_1.default)(qpqConfig)), (0, getUserDirectoryRequestEmailVerificationActionProcessor_1.default)(qpqConfig)), (0, getUserDirectoryRespondToAuthChallengeActionProcessor_1.default)(qpqConfig)));
|
|
@@ -34,6 +34,7 @@ const authenticateUser = (userPoolId, clientId, region, username, password) => _
|
|
|
34
34
|
};
|
|
35
35
|
try {
|
|
36
36
|
const response = yield cognitoClient.send(new client_cognito_identity_provider_1.AdminInitiateAuthCommand(params));
|
|
37
|
+
console.log('authenticateUser response: ', JSON.stringify(response, null, 2));
|
|
37
38
|
return (0, transformCognitoResponse_1.cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo)(response, issueDateTime);
|
|
38
39
|
}
|
|
39
40
|
catch (e) {
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AuthenticateUserResponse } from 'quidproquo-core';
|
|
2
|
+
export declare const respondToAuthChallengeChallenge: (userPoolId: string, clientId: string, region: string, username: string, session: string, attributes: Record<string, string>) => Promise<AuthenticateUserResponse>;
|
|
@@ -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.respondToAuthChallengeChallenge = 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 respondToAuthChallengeChallenge = (userPoolId, clientId, region, username, session, attributes) => __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
|
+
ChallengeName: client_cognito_identity_provider_1.ChallengeNameType.NEW_PASSWORD_REQUIRED,
|
|
23
|
+
ClientId: clientId,
|
|
24
|
+
Session: session,
|
|
25
|
+
ChallengeResponses: Object.assign({ USERNAME: username, SECRET_HASH: secretHash }, attributes),
|
|
26
|
+
};
|
|
27
|
+
console.log('params', JSON.stringify(params, null, 2));
|
|
28
|
+
const issueDateTime = new Date().toISOString();
|
|
29
|
+
const response = yield cognitoClient.send(new client_cognito_identity_provider_1.RespondToAuthChallengeCommand(params));
|
|
30
|
+
// transform the response into your custom format, similar to your refreshToken function
|
|
31
|
+
return (0, transformCognitoResponse_1.cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo)(response, issueDateTime);
|
|
32
|
+
});
|
|
33
|
+
exports.respondToAuthChallengeChallenge = respondToAuthChallengeChallenge;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AuthenticateUserResponse, AuthenticationInfo } from 'quidproquo-core';
|
|
2
|
-
import { AuthenticationResultType, AdminInitiateAuthResponse } from '@aws-sdk/client-cognito-identity-provider';
|
|
1
|
+
import { AuthenticateUserResponse, AuthenticationInfo, AuthenticateUserChallenge } from 'quidproquo-core';
|
|
2
|
+
import { AuthenticationResultType, AdminInitiateAuthResponse, ChallengeNameType } from '@aws-sdk/client-cognito-identity-provider';
|
|
3
3
|
export declare const cognitoAuthenticationResultTypeToQpqAuthenticationInfo: (authResult: AuthenticationResultType, issueDateTime: string) => AuthenticationInfo;
|
|
4
|
+
export declare const cognitoChallengeNameTypeToQpqAuthenticateUserChallenge: (cognitoChallengeName: ChallengeNameType | string | undefined) => AuthenticateUserChallenge;
|
|
4
5
|
export declare const cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo: (authResponse: AdminInitiateAuthResponse, issueDateTime: string) => AuthenticateUserResponse;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo = exports.cognitoAuthenticationResultTypeToQpqAuthenticationInfo = void 0;
|
|
3
|
+
exports.cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo = exports.cognitoChallengeNameTypeToQpqAuthenticateUserChallenge = exports.cognitoAuthenticationResultTypeToQpqAuthenticationInfo = void 0;
|
|
4
4
|
const quidproquo_core_1 = require("quidproquo-core");
|
|
5
|
+
const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
|
|
5
6
|
const cognitoAuthenticationResultTypeToQpqAuthenticationInfo = (authResult, issueDateTime) => {
|
|
6
7
|
// Parse the issueDateTime and add the expiresIn to get the expiration date
|
|
7
8
|
let issueDate = new Date(issueDateTime);
|
|
@@ -17,10 +18,22 @@ const cognitoAuthenticationResultTypeToQpqAuthenticationInfo = (authResult, issu
|
|
|
17
18
|
};
|
|
18
19
|
};
|
|
19
20
|
exports.cognitoAuthenticationResultTypeToQpqAuthenticationInfo = cognitoAuthenticationResultTypeToQpqAuthenticationInfo;
|
|
21
|
+
const cognitoChallengeNameTypeToQpqAuthenticateUserChallenge = (cognitoChallengeName) => {
|
|
22
|
+
if (!cognitoChallengeName) {
|
|
23
|
+
return quidproquo_core_1.AuthenticateUserChallenge.NONE;
|
|
24
|
+
}
|
|
25
|
+
const map = {
|
|
26
|
+
[client_cognito_identity_provider_1.ChallengeNameType.NEW_PASSWORD_REQUIRED]: quidproquo_core_1.AuthenticateUserChallenge.NEW_PASSWORD_REQUIRED,
|
|
27
|
+
};
|
|
28
|
+
// TODO: handle the NOT-IMP cases
|
|
29
|
+
const challenge = map[cognitoChallengeName] || `NOT-IMP-${cognitoChallengeName}`;
|
|
30
|
+
return challenge;
|
|
31
|
+
};
|
|
32
|
+
exports.cognitoChallengeNameTypeToQpqAuthenticateUserChallenge = cognitoChallengeNameTypeToQpqAuthenticateUserChallenge;
|
|
20
33
|
const cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo = (authResponse, issueDateTime) => {
|
|
21
34
|
const res = {
|
|
22
35
|
session: authResponse.Session,
|
|
23
|
-
challenge:
|
|
36
|
+
challenge: (0, exports.cognitoChallengeNameTypeToQpqAuthenticateUserChallenge)(authResponse.ChallengeName),
|
|
24
37
|
};
|
|
25
38
|
if (authResponse.AuthenticationResult) {
|
|
26
39
|
res.authenticationInfo = (0, exports.cognitoAuthenticationResultTypeToQpqAuthenticationInfo)(authResponse.AuthenticationResult, issueDateTime);
|