Skip to content

Commit cb6da3f

Browse files
committed
added support for secure integration config
1 parent 6980603 commit cb6da3f

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# KnownUser.V3.Cloudfront
1+
# KnownUser.V3.Cloudfront
22
The Queue-it Security Framework is used to ensure that end users cannot reach to your protected backend routes without passing the virtual queue by performing a server-side validation before processing a request. This repository is containing two AWS lambda functions you can add them in your CloudFront distribution for CloudFront Events ViewerRequest and ViewerResponse to integrate queue-it functionality for your backend.
33

44
## Introduction
@@ -13,7 +13,7 @@ After returning from the queue, the script will let user continue its request t
1313

1414
## Instruction
1515

16-
- Set your CustomerId and SecretKey in `index.js` file in ViewerRequest package
16+
- Set your CustomerId, SecretKey and API key in `index.js` file in ViewerRequest package
1717
- Create two lambda edge functions one for ViewerRequest and one for ViewerResponse and put the code from this repository there respectively.
1818
- Define your desired behaviours where you want to be protected by queue and set CloudFront events ViewerRequest and ViewerResponse to function you have already created.
1919

ViewerRequest/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
const CustomerId = "YOUR CUSTOMERID HERE";
33
const SecretKey = "YOUR SECRETE KEY HERE";
4-
4+
const APIKey = "YOUR API KEY HERE";
55

66
const querystringParser = require('querystring');
77
const QueueIT = require("./sdk/queueit-knownuserv3-sdk.js");
@@ -32,14 +32,13 @@ async function handleRequest(request) {
3232
helpers.configureKnownUserHashing();
3333
const response = {
3434
headers: {}
35-
};
36-
let configUrl = `https://${CustomerId}.queue-it.net/status/integrationconfig/${CustomerId}`;
35+
};
3736
let httpContext = httpContextProvider.getCloudFrontHttpContext(request, response);
3837
var queueitToken = querystringParser.parse(request.querystring)[knownUser.QueueITTokenKey];
3938
var requestUrl = httpContext.getHttpRequest().getAbsoluteUri();
4039
var requestUrlWithoutToken = requestUrl.replace(new RegExp("([\?&])(" + knownUser.QueueITTokenKey + "=[^&]*)", 'i'), "");
4140
requestUrlWithoutToken = requestUrlWithoutToken.replace(new RegExp("[?]$"), "");
42-
var integrationConfig = await integrationConfigProvider.getConfig(configUrl);
41+
var integrationConfig = await integrationConfigProvider.getConfig(CustomerId, APIKey);
4342

4443
var validationResult = knownUser.validateRequestByIntegrationConfig(
4544
requestUrlWithoutToken, queueitToken, integrationConfig,
@@ -103,4 +102,4 @@ async function handleRequest(request) {
103102
return request;
104103
}
105104
}
106-
}
105+
}

ViewerRequest/integrationConfigProvider.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@ const CacheTimeoutMS = 5 * 60 * 1000;
55
const RequestTimeoutMS = 1000;
66
let GlobalCache = null;
77

8-
exports.getConfig = async function (configUrl) {
8+
exports.getConfig = async function (customerId, apiKey) {
99
return new Promise((resolve, reject) => {
1010
if (isGLobalCacheValid()) {
1111
resolve(GlobalCache.integrationConfig);
1212
return;
1313
}
14-
let request = https.get(configUrl, (resp) => {
14+
const options = {
15+
hostname: `${customerId}.test.queue-it.net`,
16+
path: `/status/integrationconfig/secure/${customerId}`,
17+
method: 'GET',
18+
headers: { 'api-key': apiKey},
19+
port: 443
20+
};
21+
let request = https.get(options, (resp) => {
1522
let data = '';
1623
resp.setEncoding('utf8');
1724
resp.on('data', (chunk) => {
@@ -22,7 +29,7 @@ exports.getConfig = async function (configUrl) {
2229
var newCached = {
2330
expirationTime: (Date.now()) + CacheTimeoutMS,
2431
integrationConfig: data
25-
};
32+
};
2633
GlobalCache = newCached;
2734
resolve(GlobalCache.integrationConfig);
2835
}

ViewerRequest/queueitHelpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const CLOUDFRONT_SDK_VERSION ="1.2.1";
1+
const CLOUDFRONT_SDK_VERSION ="1.2.2";
22
const QueueIT = require("./sdk/queueit-knownuserv3-sdk.js");
33
exports.addKUPlatformVersion= function(redirectQueueUrl)
44
{

0 commit comments

Comments
 (0)