quidproquo-actionprocessor-awslambda 0.0.74 → 0.0.76
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/awsNamingUtils.d.ts +1 -0
- package/lib/awsNamingUtils.js +9 -1
- package/lib/getActionProcessor/core/event/getAPIGatewayEventActionProcessor.js +1 -1
- package/lib/getActionProcessor/core/event/utils/isAuthValid.d.ts +1 -1
- package/lib/getActionProcessor/core/event/utils/isAuthValid.js +30 -2
- package/lib/logic/apiGateway/getApiKeys.d.ts +2 -0
- package/lib/logic/apiGateway/getApiKeys.js +24 -0
- package/package.json +9 -8
package/lib/awsNamingUtils.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export declare const getQpqRuntimeResourceName: (resourceName: string, applicati
|
|
|
5
5
|
export declare const getQpqRuntimeResourceNameFromConfig: (resourceName: string, qpqConfig: QPQConfig, resourceType?: string) => string;
|
|
6
6
|
export declare const getCFExportNameUserPoolIdFromConfig: (userDirectoryName: string, qpqConfig: QPQConfig, serviceOverride?: string, applicationOverride?: string) => string;
|
|
7
7
|
export declare const getCFExportNameUserPoolClientIdFromConfig: (userDirectoryName: string, qpqConfig: QPQConfig, serviceOverride?: string, applicationOverride?: string) => string;
|
|
8
|
+
export declare const getCFExportNameApiKeyIdFromConfig: (apiKeyName: string, qpqConfig: QPQConfig, serviceOverride?: string, applicationOverride?: string) => string;
|
package/lib/awsNamingUtils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCFExportNameUserPoolClientIdFromConfig = exports.getCFExportNameUserPoolIdFromConfig = exports.getQpqRuntimeResourceNameFromConfig = exports.getQpqRuntimeResourceName = exports.getConfigRuntimeResourceNameFromConfig = exports.getConfigRuntimeResourceName = void 0;
|
|
3
|
+
exports.getCFExportNameApiKeyIdFromConfig = exports.getCFExportNameUserPoolClientIdFromConfig = exports.getCFExportNameUserPoolIdFromConfig = exports.getQpqRuntimeResourceNameFromConfig = exports.getQpqRuntimeResourceName = exports.getConfigRuntimeResourceNameFromConfig = exports.getConfigRuntimeResourceName = void 0;
|
|
4
4
|
const quidproquo_core_1 = require("quidproquo-core");
|
|
5
5
|
const getConfigRuntimeResourceName = (resourceName, application, service, environment, feature) => {
|
|
6
6
|
const baseName = `${resourceName}-${application}-${service}-${environment}`;
|
|
@@ -47,3 +47,11 @@ const getCFExportNameUserPoolClientIdFromConfig = (userDirectoryName, qpqConfig,
|
|
|
47
47
|
return (0, exports.getQpqRuntimeResourceName)(userDirectoryName, application, service, environment, feature, 'user-pool-client-id-export');
|
|
48
48
|
};
|
|
49
49
|
exports.getCFExportNameUserPoolClientIdFromConfig = getCFExportNameUserPoolClientIdFromConfig;
|
|
50
|
+
const getCFExportNameApiKeyIdFromConfig = (apiKeyName, qpqConfig, serviceOverride, applicationOverride) => {
|
|
51
|
+
const application = applicationOverride || quidproquo_core_1.qpqCoreUtils.getApplicationName(qpqConfig);
|
|
52
|
+
const service = serviceOverride || quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
53
|
+
const environment = quidproquo_core_1.qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig);
|
|
54
|
+
const feature = quidproquo_core_1.qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
|
|
55
|
+
return (0, exports.getQpqRuntimeResourceName)(apiKeyName, application, service, environment, feature, 'api-key-id-export');
|
|
56
|
+
};
|
|
57
|
+
exports.getCFExportNameApiKeyIdFromConfig = getCFExportNameApiKeyIdFromConfig;
|
|
@@ -59,7 +59,7 @@ const getProcessAutoRespond = (qpqConfig) => {
|
|
|
59
59
|
headers: quidproquo_webserver_1.qpqWebServerUtils.getCorsHeaders(qpqConfig, payload.matchResult.config || {}, payload.transformedEventParams.headers),
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
const authValid = yield (0, isAuthValid_1.isAuthValid)(qpqConfig, quidproquo_webserver_1.qpqWebServerUtils.getHeaderValue('Authorization', payload.transformedEventParams.headers), (_a = payload.matchResult.config) === null || _a === void 0 ? void 0 : _a.routeAuthSettings);
|
|
62
|
+
const authValid = yield (0, isAuthValid_1.isAuthValid)(qpqConfig, quidproquo_webserver_1.qpqWebServerUtils.getHeaderValue('Authorization', payload.transformedEventParams.headers), quidproquo_webserver_1.qpqWebServerUtils.getHeaderValue('x-api-key', payload.transformedEventParams.headers), (_a = payload.matchResult.config) === null || _a === void 0 ? void 0 : _a.routeAuthSettings);
|
|
63
63
|
if (!authValid) {
|
|
64
64
|
return (0, quidproquo_core_1.actionResult)({
|
|
65
65
|
status: 401,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { QPQConfig } from 'quidproquo-core';
|
|
2
2
|
import { RouteAuthSettings } from 'quidproquo-webserver';
|
|
3
|
-
export declare const isAuthValid: (qpqConfig: QPQConfig, authHeader?: string | null, authSettings?: RouteAuthSettings) => Promise<boolean>;
|
|
3
|
+
export declare const isAuthValid: (qpqConfig: QPQConfig, authHeader?: string | null, apiKeyHeader?: string | null, authSettings?: RouteAuthSettings) => Promise<boolean>;
|
|
@@ -13,10 +13,11 @@ exports.isAuthValid = void 0;
|
|
|
13
13
|
const quidproquo_core_1 = require("quidproquo-core");
|
|
14
14
|
const verifyJwt_1 = require("../../../../logic/cognito/verifyJwt");
|
|
15
15
|
const getExportedValue_1 = require("../../../../logic/cloudformation/getExportedValue");
|
|
16
|
+
const getApiKeys_1 = require("../../../../logic/apiGateway/getApiKeys");
|
|
16
17
|
const awsNamingUtils_1 = require("../../../../awsNamingUtils");
|
|
17
|
-
const
|
|
18
|
+
const isAuthValidForCognito = (qpqConfig, authSettings, authHeader) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
19
|
// If there are no auth settings ~ Its valid.
|
|
19
|
-
if (!authSettings
|
|
20
|
+
if (!authSettings.userDirectoryName) {
|
|
20
21
|
return true;
|
|
21
22
|
}
|
|
22
23
|
// We need a header to be able to auth
|
|
@@ -38,4 +39,31 @@ const isAuthValid = (qpqConfig, authHeader, authSettings) => __awaiter(void 0, v
|
|
|
38
39
|
// Verify the token
|
|
39
40
|
return yield (0, verifyJwt_1.verifyJwt)(accessToken, userPoolId, userPoolClientId, 'access');
|
|
40
41
|
});
|
|
42
|
+
const isAuthValidForApiKeys = (qpqConfig, authSettings, apiKeyHeader) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const apiKeys = authSettings.apiKeys || [];
|
|
44
|
+
if (apiKeys.length === 0) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
|
|
48
|
+
const application = quidproquo_core_1.qpqCoreUtils.getApplicationName(qpqConfig);
|
|
49
|
+
const service = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
50
|
+
const environment = quidproquo_core_1.qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig);
|
|
51
|
+
const feature = quidproquo_core_1.qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
|
|
52
|
+
const realApiKeys = yield (0, getApiKeys_1.getApiKeys)(region, ...apiKeys.map((apiKey) => {
|
|
53
|
+
const apiKeyApplication = apiKey.applicationName || application;
|
|
54
|
+
const apiKeyService = apiKey.serviceName || service;
|
|
55
|
+
return (0, awsNamingUtils_1.getConfigRuntimeResourceName)(apiKey.name, apiKeyApplication, apiKeyService, environment, feature);
|
|
56
|
+
}));
|
|
57
|
+
const index = realApiKeys.findIndex((apiKey) => apiKey.value === apiKeyHeader);
|
|
58
|
+
return index >= 0;
|
|
59
|
+
});
|
|
60
|
+
const isAuthValid = (qpqConfig, authHeader, apiKeyHeader, authSettings) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
// If there are no auth settings ~ Its valid.
|
|
62
|
+
if (!authSettings) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
const cognitoValid = yield isAuthValidForCognito(qpqConfig, authSettings, authHeader);
|
|
66
|
+
const authKeysValid = yield isAuthValidForApiKeys(qpqConfig, authSettings, apiKeyHeader);
|
|
67
|
+
return cognitoValid && authKeysValid;
|
|
68
|
+
});
|
|
41
69
|
exports.isAuthValid = isAuthValid;
|
|
@@ -0,0 +1,24 @@
|
|
|
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.getApiKeys = void 0;
|
|
13
|
+
const client_api_gateway_1 = require("@aws-sdk/client-api-gateway");
|
|
14
|
+
const getApiKeys = (region, ...keyNames) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
var _a;
|
|
16
|
+
const apiGatewayClient = new client_api_gateway_1.APIGatewayClient({ region });
|
|
17
|
+
const input = {
|
|
18
|
+
includeValues: true,
|
|
19
|
+
limit: 500,
|
|
20
|
+
};
|
|
21
|
+
const res = yield apiGatewayClient.send(new client_api_gateway_1.GetApiKeysCommand(input));
|
|
22
|
+
return (((_a = res.items) === null || _a === void 0 ? void 0 : _a.filter((i) => keyNames.indexOf(i.name) >= 0).map((i) => ({ name: i.name, value: i.value, description: i.description }))) || []);
|
|
23
|
+
});
|
|
24
|
+
exports.getApiKeys = getApiKeys;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quidproquo-actionprocessor-awslambda",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.76",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.js",
|
|
@@ -25,14 +25,15 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/joe-coady/quidproquo#readme",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aws-sdk/client-
|
|
29
|
-
"@aws-sdk/client-
|
|
30
|
-
"@aws-sdk/client-
|
|
31
|
-
"@aws-sdk/client-
|
|
32
|
-
"@aws-sdk/client-
|
|
33
|
-
"@aws-sdk/client-
|
|
28
|
+
"@aws-sdk/client-api-gateway": "^3.278.0",
|
|
29
|
+
"@aws-sdk/client-cloudformation": "^3.278.0",
|
|
30
|
+
"@aws-sdk/client-cognito-identity-provider": "^3.278.0",
|
|
31
|
+
"@aws-sdk/client-s3": "^3.278.0",
|
|
32
|
+
"@aws-sdk/client-secrets-manager": "^3.278.0",
|
|
33
|
+
"@aws-sdk/client-sqs": "^3.278.0",
|
|
34
|
+
"@aws-sdk/client-ssm": "^3.278.0",
|
|
34
35
|
"aws-jwt-verify": "^3.4.0",
|
|
35
|
-
"aws-sdk": "^2.
|
|
36
|
+
"aws-sdk": "^2.1322.0",
|
|
36
37
|
"node-match-path": "^0.6.3",
|
|
37
38
|
"quidproquo-core": "*",
|
|
38
39
|
"quidproquo-webserver": "*"
|