quidproquo-actionprocessor-awslambda 0.0.219 → 0.0.220

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/lib/commonjs/getActionProcessor/core/event/cognito/createAuthChallenge/getRecords.js +2 -2
  2. package/lib/commonjs/getActionProcessor/core/event/cognito/defineAuthChallenge/getRecords.js +8 -2
  3. package/lib/commonjs/getActionProcessor/core/event/cognito/utils/getChallengeSessionFromCognitoTriggerEventSession.d.ts +3 -0
  4. package/lib/commonjs/getActionProcessor/core/event/cognito/utils/getChallengeSessionFromCognitoTriggerEventSession.js +14 -0
  5. package/lib/commonjs/getActionProcessor/core/event/cognito/utils/index.d.ts +1 -0
  6. package/lib/commonjs/getActionProcessor/core/event/cognito/{verifyAuthChallenge/utils → utils}/index.js +1 -1
  7. package/lib/commonjs/getActionProcessor/core/event/cognito/verifyAuthChallenge/getRecords.js +1 -1
  8. package/lib/commonjs/getActionProcessor/core/userDirectory/getUserDirectoryRespondToAuthChallengeActionProcessor.js +16 -1
  9. package/lib/commonjs/logic/cognito/respondToAuthChallengeChallenge.d.ts +2 -1
  10. package/lib/commonjs/logic/cognito/respondToAuthChallengeChallenge.js +2 -2
  11. package/lib/commonjs/logic/cognito/utils/transformCognitoResponse.js +4 -1
  12. package/lib/esm/getActionProcessor/core/event/cognito/createAuthChallenge/getRecords.js +2 -2
  13. package/lib/esm/getActionProcessor/core/event/cognito/defineAuthChallenge/getRecords.js +8 -2
  14. package/lib/esm/getActionProcessor/core/event/cognito/utils/getChallengeSessionFromCognitoTriggerEventSession.d.ts +3 -0
  15. package/lib/esm/getActionProcessor/core/event/cognito/utils/getChallengeSessionFromCognitoTriggerEventSession.js +10 -0
  16. package/lib/esm/getActionProcessor/core/event/cognito/utils/index.d.ts +1 -0
  17. package/lib/esm/getActionProcessor/core/event/cognito/utils/index.js +1 -0
  18. package/lib/esm/getActionProcessor/core/event/cognito/verifyAuthChallenge/getRecords.js +1 -1
  19. package/lib/esm/getActionProcessor/core/userDirectory/getUserDirectoryRespondToAuthChallengeActionProcessor.js +17 -2
  20. package/lib/esm/logic/cognito/respondToAuthChallengeChallenge.d.ts +2 -1
  21. package/lib/esm/logic/cognito/respondToAuthChallengeChallenge.js +3 -3
  22. package/lib/esm/logic/cognito/utils/transformCognitoResponse.js +6 -3
  23. package/package.json +5 -5
  24. package/lib/commonjs/getActionProcessor/core/event/cognito/createAuthChallenge/utils/getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent.d.ts +0 -3
  25. package/lib/commonjs/getActionProcessor/core/event/cognito/createAuthChallenge/utils/getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent.js +0 -14
  26. package/lib/commonjs/getActionProcessor/core/event/cognito/createAuthChallenge/utils/index.d.ts +0 -1
  27. package/lib/commonjs/getActionProcessor/core/event/cognito/createAuthChallenge/utils/index.js +0 -17
  28. package/lib/commonjs/getActionProcessor/core/event/cognito/verifyAuthChallenge/utils/getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent.d.ts +0 -3
  29. package/lib/commonjs/getActionProcessor/core/event/cognito/verifyAuthChallenge/utils/getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent.js +0 -14
  30. package/lib/commonjs/getActionProcessor/core/event/cognito/verifyAuthChallenge/utils/index.d.ts +0 -1
  31. package/lib/esm/getActionProcessor/core/event/cognito/createAuthChallenge/utils/getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent.d.ts +0 -3
  32. package/lib/esm/getActionProcessor/core/event/cognito/createAuthChallenge/utils/getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent.js +0 -10
  33. package/lib/esm/getActionProcessor/core/event/cognito/createAuthChallenge/utils/index.d.ts +0 -1
  34. package/lib/esm/getActionProcessor/core/event/cognito/createAuthChallenge/utils/index.js +0 -1
  35. package/lib/esm/getActionProcessor/core/event/cognito/verifyAuthChallenge/utils/getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent.d.ts +0 -3
  36. package/lib/esm/getActionProcessor/core/event/cognito/verifyAuthChallenge/utils/getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent.js +0 -10
  37. package/lib/esm/getActionProcessor/core/event/cognito/verifyAuthChallenge/utils/index.d.ts +0 -1
  38. package/lib/esm/getActionProcessor/core/event/cognito/verifyAuthChallenge/utils/index.js +0 -1
@@ -11,12 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const quidproquo_core_1 = require("quidproquo-core");
13
13
  const cognitoAttributeMap_1 = require("../../../../../logic/cognito/cognitoAttributeMap");
14
- const utils_1 = require("./utils");
14
+ const utils_1 = require("../utils");
15
15
  const getProcessGetRecords = (qpqConfig) => {
16
16
  return ({ eventParams: [event, context] }) => __awaiter(void 0, void 0, void 0, function* () {
17
17
  const internalEventRecord = {
18
18
  userName: event.userName,
19
- session: (0, utils_1.getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent)(event),
19
+ session: (0, utils_1.getChallengeSessionFromCognitoTriggerEventSession)(event.request.session),
20
20
  userAttributes: (0, cognitoAttributeMap_1.getQpqAttributesFromCognitoStringMap)(event.request.userAttributes),
21
21
  };
22
22
  return (0, quidproquo_core_1.actionResult)([internalEventRecord]);
@@ -10,9 +10,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const quidproquo_core_1 = require("quidproquo-core");
13
+ const cognitoAttributeMap_1 = require("../../../../../logic/cognito/cognitoAttributeMap");
14
+ const utils_1 = require("../utils");
13
15
  const getProcessGetRecords = (qpqConfig) => {
14
- return ({ eventParams: [customMessageTriggerEvent, context] }) => __awaiter(void 0, void 0, void 0, function* () {
15
- const internalEventRecord = {};
16
+ return ({ eventParams: [event, context] }) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const internalEventRecord = {
18
+ userName: event.userName,
19
+ session: (0, utils_1.getChallengeSessionFromCognitoTriggerEventSession)(event.request.session),
20
+ userAttributes: (0, cognitoAttributeMap_1.getQpqAttributesFromCognitoStringMap)(event.request.userAttributes),
21
+ };
16
22
  return (0, quidproquo_core_1.actionResult)([internalEventRecord]);
17
23
  });
18
24
  };
@@ -0,0 +1,3 @@
1
+ import { DefineAuthChallengeTriggerEvent } from 'aws-lambda';
2
+ import { ChallengeSession } from 'quidproquo-core';
3
+ export declare const getChallengeSessionFromCognitoTriggerEventSession: (session: DefineAuthChallengeTriggerEvent['request']['session']) => ChallengeSession;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getChallengeSessionFromCognitoTriggerEventSession = void 0;
4
+ const getChallengeSessionFromCognitoTriggerEventSession = (session) => {
5
+ const challengeSession = session.map((c) => {
6
+ const result = {
7
+ challengeName: c.challengeMetadata || '',
8
+ challengeResult: c.challengeResult,
9
+ };
10
+ return result;
11
+ });
12
+ return challengeSession;
13
+ };
14
+ exports.getChallengeSessionFromCognitoTriggerEventSession = getChallengeSessionFromCognitoTriggerEventSession;
@@ -0,0 +1 @@
1
+ export * from './getChallengeSessionFromCognitoTriggerEventSession';
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent"), exports);
17
+ __exportStar(require("./getChallengeSessionFromCognitoTriggerEventSession"), exports);
@@ -14,7 +14,7 @@ const cognitoAttributeMap_1 = require("../../../../../logic/cognito/cognitoAttri
14
14
  const getProcessGetRecords = (qpqConfig) => {
15
15
  return ({ eventParams: [event, context] }) => __awaiter(void 0, void 0, void 0, function* () {
16
16
  const internalEventRecord = {
17
- challengeAnswer: event.request.challengeAnswer,
17
+ challengeAnswer: event.request.challengeAnswer ? JSON.parse(event.request.challengeAnswer) : {},
18
18
  userAttributes: (0, cognitoAttributeMap_1.getQpqAttributesFromCognitoStringMap)(event.request.userAttributes),
19
19
  userNotFound: event.request.userNotFound,
20
20
  privateChallengeParameters: event.request.privateChallengeParameters,
@@ -13,22 +13,37 @@ const quidproquo_core_1 = require("quidproquo-core");
13
13
  const awsNamingUtils_1 = require("../../../awsNamingUtils");
14
14
  const getExportedValue_1 = require("../../../logic/cloudformation/getExportedValue");
15
15
  const respondToAuthChallengeChallenge_1 = require("../../../logic/cognito/respondToAuthChallengeChallenge");
16
+ const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
16
17
  const anyAuthChallengeToCognitoAttributes = (authChallenge) => {
17
18
  switch (authChallenge.challenge) {
18
19
  case quidproquo_core_1.AuthenticateUserChallenge.NEW_PASSWORD_REQUIRED:
19
20
  return {
20
21
  NEW_PASSWORD: authChallenge.newPassword,
21
22
  };
23
+ case quidproquo_core_1.AuthenticateUserChallenge.CUSTOM_CHALLENGE:
24
+ return {
25
+ ANSWER: JSON.stringify(authChallenge.challengeAnswer),
26
+ };
22
27
  default:
23
28
  return {};
24
29
  }
25
30
  };
31
+ const anyAuthChallengeToCognitoChallengeName = (authChallenge) => {
32
+ switch (authChallenge.challenge) {
33
+ case quidproquo_core_1.AuthenticateUserChallenge.NEW_PASSWORD_REQUIRED:
34
+ return client_cognito_identity_provider_1.ChallengeNameType.NEW_PASSWORD_REQUIRED;
35
+ case quidproquo_core_1.AuthenticateUserChallenge.CUSTOM_CHALLENGE:
36
+ return client_cognito_identity_provider_1.ChallengeNameType.CUSTOM_CHALLENGE;
37
+ default:
38
+ throw new Error(`Unknown challenge`);
39
+ }
40
+ };
26
41
  const getUserDirectoryRespondToAuthChallengeActionProcessor = (qpqConfig) => {
27
42
  return ({ userDirectoryName, authChallenge }) => __awaiter(void 0, void 0, void 0, function* () {
28
43
  const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
29
44
  const userPoolId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameUserPoolIdFromConfig)(userDirectoryName, qpqConfig), region);
30
45
  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));
46
+ const response = yield (0, respondToAuthChallengeChallenge_1.respondToAuthChallengeChallenge)(userPoolId, userPoolClientId, region, authChallenge.username, authChallenge.session, anyAuthChallengeToCognitoChallengeName(authChallenge), anyAuthChallengeToCognitoAttributes(authChallenge));
32
47
  return (0, quidproquo_core_1.actionResult)(response);
33
48
  });
34
49
  };
@@ -1,2 +1,3 @@
1
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>;
2
+ import { ChallengeNameType } from '@aws-sdk/client-cognito-identity-provider';
3
+ export declare const respondToAuthChallengeChallenge: (userPoolId: string, clientId: string, region: string, username: string, session: string, challengeNameType: ChallengeNameType, attributes: Record<string, string>) => Promise<AuthenticateUserResponse>;
@@ -15,12 +15,12 @@ const calculateSecretHash_1 = require("./utils/calculateSecretHash");
15
15
  const getUserPoolClientSecret_1 = require("./getUserPoolClientSecret");
16
16
  const transformCognitoResponse_1 = require("./utils/transformCognitoResponse");
17
17
  const createAwsClient_1 = require("../createAwsClient");
18
- const respondToAuthChallengeChallenge = (userPoolId, clientId, region, username, session, attributes) => __awaiter(void 0, void 0, void 0, function* () {
18
+ const respondToAuthChallengeChallenge = (userPoolId, clientId, region, username, session, challengeNameType, attributes) => __awaiter(void 0, void 0, void 0, function* () {
19
19
  const cognitoClient = (0, createAwsClient_1.createAwsClient)(client_cognito_identity_provider_1.CognitoIdentityProviderClient, { region });
20
20
  const clientSecret = yield (0, getUserPoolClientSecret_1.getUserPoolClientSecret)(userPoolId, clientId, region);
21
21
  const secretHash = (0, calculateSecretHash_1.calculateSecretHash)(username, clientId, clientSecret);
22
22
  const params = {
23
- ChallengeName: client_cognito_identity_provider_1.ChallengeNameType.NEW_PASSWORD_REQUIRED,
23
+ ChallengeName: challengeNameType,
24
24
  ClientId: clientId,
25
25
  Session: session,
26
26
  ChallengeResponses: Object.assign({ USERNAME: username, SECRET_HASH: secretHash }, attributes),
@@ -24,16 +24,19 @@ const cognitoChallengeNameTypeToQpqAuthenticateUserChallenge = (cognitoChallenge
24
24
  }
25
25
  const map = {
26
26
  [client_cognito_identity_provider_1.ChallengeNameType.NEW_PASSWORD_REQUIRED]: quidproquo_core_1.AuthenticateUserChallenge.NEW_PASSWORD_REQUIRED,
27
+ [client_cognito_identity_provider_1.ChallengeNameType.CUSTOM_CHALLENGE]: quidproquo_core_1.AuthenticateUserChallenge.CUSTOM_CHALLENGE,
27
28
  };
28
29
  // TODO: handle the NOT-IMP cases
29
- const challenge = map[cognitoChallengeName] || `NOT-IMP-${cognitoChallengeName}`;
30
+ const challenge = map[cognitoChallengeName] || `QPQ-NOT-IMP-${cognitoChallengeName}`;
30
31
  return challenge;
31
32
  };
32
33
  exports.cognitoChallengeNameTypeToQpqAuthenticateUserChallenge = cognitoChallengeNameTypeToQpqAuthenticateUserChallenge;
33
34
  const cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo = (authResponse, issueDateTime) => {
35
+ console.log('authResponse XYZ', authResponse);
34
36
  const res = {
35
37
  session: authResponse.Session,
36
38
  challenge: (0, exports.cognitoChallengeNameTypeToQpqAuthenticateUserChallenge)(authResponse.ChallengeName),
39
+ challengeParameters: authResponse.ChallengeParameters,
37
40
  };
38
41
  if (authResponse.AuthenticationResult) {
39
42
  res.authenticationInfo = (0, exports.cognitoAuthenticationResultTypeToQpqAuthenticationInfo)(authResponse.AuthenticationResult, issueDateTime);
@@ -1,11 +1,11 @@
1
1
  import { EventActionType, actionResult } from 'quidproquo-core';
2
2
  import { getQpqAttributesFromCognitoStringMap } from '../../../../../logic/cognito/cognitoAttributeMap';
3
- import { getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent } from './utils';
3
+ import { getChallengeSessionFromCognitoTriggerEventSession } from '../utils';
4
4
  const getProcessGetRecords = (qpqConfig) => {
5
5
  return async ({ eventParams: [event, context] }) => {
6
6
  const internalEventRecord = {
7
7
  userName: event.userName,
8
- session: getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent(event),
8
+ session: getChallengeSessionFromCognitoTriggerEventSession(event.request.session),
9
9
  userAttributes: getQpqAttributesFromCognitoStringMap(event.request.userAttributes),
10
10
  };
11
11
  return actionResult([internalEventRecord]);
@@ -1,7 +1,13 @@
1
1
  import { EventActionType, actionResult } from 'quidproquo-core';
2
+ import { getQpqAttributesFromCognitoStringMap } from '../../../../../logic/cognito/cognitoAttributeMap';
3
+ import { getChallengeSessionFromCognitoTriggerEventSession } from '../utils';
2
4
  const getProcessGetRecords = (qpqConfig) => {
3
- return async ({ eventParams: [customMessageTriggerEvent, context] }) => {
4
- const internalEventRecord = {};
5
+ return async ({ eventParams: [event, context] }) => {
6
+ const internalEventRecord = {
7
+ userName: event.userName,
8
+ session: getChallengeSessionFromCognitoTriggerEventSession(event.request.session),
9
+ userAttributes: getQpqAttributesFromCognitoStringMap(event.request.userAttributes),
10
+ };
5
11
  return actionResult([internalEventRecord]);
6
12
  };
7
13
  };
@@ -0,0 +1,3 @@
1
+ import { DefineAuthChallengeTriggerEvent } from 'aws-lambda';
2
+ import { ChallengeSession } from 'quidproquo-core';
3
+ export declare const getChallengeSessionFromCognitoTriggerEventSession: (session: DefineAuthChallengeTriggerEvent['request']['session']) => ChallengeSession;
@@ -0,0 +1,10 @@
1
+ export const getChallengeSessionFromCognitoTriggerEventSession = (session) => {
2
+ const challengeSession = session.map((c) => {
3
+ const result = {
4
+ challengeName: c.challengeMetadata || '',
5
+ challengeResult: c.challengeResult,
6
+ };
7
+ return result;
8
+ });
9
+ return challengeSession;
10
+ };
@@ -0,0 +1 @@
1
+ export * from './getChallengeSessionFromCognitoTriggerEventSession';
@@ -0,0 +1 @@
1
+ export * from './getChallengeSessionFromCognitoTriggerEventSession';
@@ -3,7 +3,7 @@ import { getQpqAttributesFromCognitoStringMap } from '../../../../../logic/cogni
3
3
  const getProcessGetRecords = (qpqConfig) => {
4
4
  return async ({ eventParams: [event, context] }) => {
5
5
  const internalEventRecord = {
6
- challengeAnswer: event.request.challengeAnswer,
6
+ challengeAnswer: event.request.challengeAnswer ? JSON.parse(event.request.challengeAnswer) : {},
7
7
  userAttributes: getQpqAttributesFromCognitoStringMap(event.request.userAttributes),
8
8
  userNotFound: event.request.userNotFound,
9
9
  privateChallengeParameters: event.request.privateChallengeParameters,
@@ -1,23 +1,38 @@
1
1
  import { actionResult, qpqCoreUtils, UserDirectoryActionType, AuthenticateUserChallenge, } from 'quidproquo-core';
2
- import { getCFExportNameUserPoolIdFromConfig, getCFExportNameUserPoolClientIdFromConfig, } from '../../../awsNamingUtils';
2
+ import { getCFExportNameUserPoolIdFromConfig, getCFExportNameUserPoolClientIdFromConfig } from '../../../awsNamingUtils';
3
3
  import { getExportedValue } from '../../../logic/cloudformation/getExportedValue';
4
4
  import { respondToAuthChallengeChallenge } from '../../../logic/cognito/respondToAuthChallengeChallenge';
5
+ import { ChallengeNameType } from '@aws-sdk/client-cognito-identity-provider';
5
6
  const anyAuthChallengeToCognitoAttributes = (authChallenge) => {
6
7
  switch (authChallenge.challenge) {
7
8
  case AuthenticateUserChallenge.NEW_PASSWORD_REQUIRED:
8
9
  return {
9
10
  NEW_PASSWORD: authChallenge.newPassword,
10
11
  };
12
+ case AuthenticateUserChallenge.CUSTOM_CHALLENGE:
13
+ return {
14
+ ANSWER: JSON.stringify(authChallenge.challengeAnswer),
15
+ };
11
16
  default:
12
17
  return {};
13
18
  }
14
19
  };
20
+ const anyAuthChallengeToCognitoChallengeName = (authChallenge) => {
21
+ switch (authChallenge.challenge) {
22
+ case AuthenticateUserChallenge.NEW_PASSWORD_REQUIRED:
23
+ return ChallengeNameType.NEW_PASSWORD_REQUIRED;
24
+ case AuthenticateUserChallenge.CUSTOM_CHALLENGE:
25
+ return ChallengeNameType.CUSTOM_CHALLENGE;
26
+ default:
27
+ throw new Error(`Unknown challenge`);
28
+ }
29
+ };
15
30
  const getUserDirectoryRespondToAuthChallengeActionProcessor = (qpqConfig) => {
16
31
  return async ({ userDirectoryName, authChallenge }) => {
17
32
  const region = qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
18
33
  const userPoolId = await getExportedValue(getCFExportNameUserPoolIdFromConfig(userDirectoryName, qpqConfig), region);
19
34
  const userPoolClientId = await getExportedValue(getCFExportNameUserPoolClientIdFromConfig(userDirectoryName, qpqConfig), region);
20
- const response = await respondToAuthChallengeChallenge(userPoolId, userPoolClientId, region, authChallenge.username, authChallenge.session, anyAuthChallengeToCognitoAttributes(authChallenge));
35
+ const response = await respondToAuthChallengeChallenge(userPoolId, userPoolClientId, region, authChallenge.username, authChallenge.session, anyAuthChallengeToCognitoChallengeName(authChallenge), anyAuthChallengeToCognitoAttributes(authChallenge));
21
36
  return actionResult(response);
22
37
  };
23
38
  };
@@ -1,2 +1,3 @@
1
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>;
2
+ import { ChallengeNameType } from '@aws-sdk/client-cognito-identity-provider';
3
+ export declare const respondToAuthChallengeChallenge: (userPoolId: string, clientId: string, region: string, username: string, session: string, challengeNameType: ChallengeNameType, attributes: Record<string, string>) => Promise<AuthenticateUserResponse>;
@@ -1,14 +1,14 @@
1
- import { CognitoIdentityProviderClient, RespondToAuthChallengeCommand, ChallengeNameType, } from '@aws-sdk/client-cognito-identity-provider';
1
+ import { CognitoIdentityProviderClient, RespondToAuthChallengeCommand, } from '@aws-sdk/client-cognito-identity-provider';
2
2
  import { calculateSecretHash } from './utils/calculateSecretHash';
3
3
  import { getUserPoolClientSecret } from './getUserPoolClientSecret';
4
4
  import { cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo } from './utils/transformCognitoResponse';
5
5
  import { createAwsClient } from '../createAwsClient';
6
- export const respondToAuthChallengeChallenge = async (userPoolId, clientId, region, username, session, attributes) => {
6
+ export const respondToAuthChallengeChallenge = async (userPoolId, clientId, region, username, session, challengeNameType, attributes) => {
7
7
  const cognitoClient = createAwsClient(CognitoIdentityProviderClient, { region });
8
8
  const clientSecret = await getUserPoolClientSecret(userPoolId, clientId, region);
9
9
  const secretHash = calculateSecretHash(username, clientId, clientSecret);
10
10
  const params = {
11
- ChallengeName: ChallengeNameType.NEW_PASSWORD_REQUIRED,
11
+ ChallengeName: challengeNameType,
12
12
  ClientId: clientId,
13
13
  Session: session,
14
14
  ChallengeResponses: {
@@ -1,5 +1,5 @@
1
- import { AuthenticateUserChallenge, } from 'quidproquo-core';
2
- import { ChallengeNameType, } from '@aws-sdk/client-cognito-identity-provider';
1
+ import { AuthenticateUserChallenge } from 'quidproquo-core';
2
+ import { ChallengeNameType } from '@aws-sdk/client-cognito-identity-provider';
3
3
  export const cognitoAuthenticationResultTypeToQpqAuthenticationInfo = (authResult, issueDateTime) => {
4
4
  // Parse the issueDateTime and add the expiresIn to get the expiration date
5
5
  let issueDate = new Date(issueDateTime);
@@ -20,15 +20,18 @@ export const cognitoChallengeNameTypeToQpqAuthenticateUserChallenge = (cognitoCh
20
20
  }
21
21
  const map = {
22
22
  [ChallengeNameType.NEW_PASSWORD_REQUIRED]: AuthenticateUserChallenge.NEW_PASSWORD_REQUIRED,
23
+ [ChallengeNameType.CUSTOM_CHALLENGE]: AuthenticateUserChallenge.CUSTOM_CHALLENGE,
23
24
  };
24
25
  // TODO: handle the NOT-IMP cases
25
- const challenge = map[cognitoChallengeName] || `NOT-IMP-${cognitoChallengeName}`;
26
+ const challenge = map[cognitoChallengeName] || `QPQ-NOT-IMP-${cognitoChallengeName}`;
26
27
  return challenge;
27
28
  };
28
29
  export const cognitoAdminInitiateAuthResponseToQpqAuthenticationInfo = (authResponse, issueDateTime) => {
30
+ console.log('authResponse XYZ', authResponse);
29
31
  const res = {
30
32
  session: authResponse.Session,
31
33
  challenge: cognitoChallengeNameTypeToQpqAuthenticateUserChallenge(authResponse.ChallengeName),
34
+ challengeParameters: authResponse.ChallengeParameters,
32
35
  };
33
36
  if (authResponse.AuthenticationResult) {
34
37
  res.authenticationInfo = cognitoAuthenticationResultTypeToQpqAuthenticationInfo(authResponse.AuthenticationResult, issueDateTime);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-actionprocessor-awslambda",
3
- "version": "0.0.219",
3
+ "version": "0.0.220",
4
4
  "description": "",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/esm/index.js",
@@ -51,9 +51,9 @@
51
51
  "lodash": "^4.17.21",
52
52
  "node-cache": "^5.1.2",
53
53
  "node-match-path": "^0.6.3",
54
- "quidproquo-config-aws": "0.0.219",
55
- "quidproquo-core": "0.0.219",
56
- "quidproquo-webserver": "0.0.219"
54
+ "quidproquo-config-aws": "0.0.220",
55
+ "quidproquo-core": "0.0.220",
56
+ "quidproquo-webserver": "0.0.220"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/aws-lambda": "^8.10.109",
@@ -61,7 +61,7 @@
61
61
  "@types/jsonwebtoken": "^9.0.2",
62
62
  "@types/lodash": "^4.14.194",
63
63
  "@types/node": "^18.11.9",
64
- "quidproquo-tsconfig": "0.0.219",
64
+ "quidproquo-tsconfig": "0.0.220",
65
65
  "typescript": "^4.9.3"
66
66
  }
67
67
  }
@@ -1,3 +0,0 @@
1
- import { CreateAuthChallengeTriggerEvent } from 'aws-lambda';
2
- import { ChallengeSession } from 'quidproquo-core';
3
- export declare const getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent: (event: CreateAuthChallengeTriggerEvent) => ChallengeSession;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent = void 0;
4
- const getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent = (event) => {
5
- const session = event.request.session.map((c) => {
6
- const result = {
7
- challengeName: c.challengeMetadata || '',
8
- challengeResult: c.challengeResult,
9
- };
10
- return result;
11
- });
12
- return session;
13
- };
14
- exports.getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent = getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent;
@@ -1 +0,0 @@
1
- export * from './getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent';
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent"), exports);
@@ -1,3 +0,0 @@
1
- import { CreateAuthChallengeTriggerEvent } from 'aws-lambda';
2
- import { ChallengeSession } from 'quidproquo-core';
3
- export declare const getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent: (event: CreateAuthChallengeTriggerEvent) => ChallengeSession;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent = void 0;
4
- const getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent = (event) => {
5
- const session = event.request.session.map((c) => {
6
- const result = {
7
- challengeName: c.challengeMetadata || '',
8
- challengeResult: c.challengeResult,
9
- };
10
- return result;
11
- });
12
- return session;
13
- };
14
- exports.getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent = getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent;
@@ -1 +0,0 @@
1
- export * from './getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent';
@@ -1,3 +0,0 @@
1
- import { CreateAuthChallengeTriggerEvent } from 'aws-lambda';
2
- import { ChallengeSession } from 'quidproquo-core';
3
- export declare const getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent: (event: CreateAuthChallengeTriggerEvent) => ChallengeSession;
@@ -1,10 +0,0 @@
1
- export const getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent = (event) => {
2
- const session = event.request.session.map((c) => {
3
- const result = {
4
- challengeName: c.challengeMetadata || '',
5
- challengeResult: c.challengeResult,
6
- };
7
- return result;
8
- });
9
- return session;
10
- };
@@ -1 +0,0 @@
1
- export * from './getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent';
@@ -1 +0,0 @@
1
- export * from './getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent';
@@ -1,3 +0,0 @@
1
- import { CreateAuthChallengeTriggerEvent } from 'aws-lambda';
2
- import { ChallengeSession } from 'quidproquo-core';
3
- export declare const getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent: (event: CreateAuthChallengeTriggerEvent) => ChallengeSession;
@@ -1,10 +0,0 @@
1
- export const getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent = (event) => {
2
- const session = event.request.session.map((c) => {
3
- const result = {
4
- challengeName: c.challengeMetadata || '',
5
- challengeResult: c.challengeResult,
6
- };
7
- return result;
8
- });
9
- return session;
10
- };
@@ -1 +0,0 @@
1
- export * from './getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent';
@@ -1 +0,0 @@
1
- export * from './getChallengeSessionFromCognitoCreateAuthChallengeTriggerEvent';