Skip to content

Commit 325758f

Browse files
committed
Added hashed IP validation in queue it token
1 parent eeaacb3 commit 325758f

31 files changed

Lines changed: 336 additions & 263 deletions

README.md

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# KnownUser.V3.Javascript
22
Before getting started please read the [documentation](https://github.com/queueit/Documentation/tree/main/serverside-connectors) to get acquainted with server-side connectors.
33

4-
Connector was developed with TypeScript and verified using Nodejs v.8.12 and Express v.4.16.
4+
The connector was developed with TypeScript and verified using Nodejs v.8.12 and Express v.4.16.
55

66
You can find the latest released version [here](https://github.com/queueit/KnownUser.V3.Javascript/releases/latest). or download latest npm package from [here](https://www.npmjs.com/package/queueit-knownuser).
77

@@ -10,9 +10,13 @@ The KnownUser validation must be done on *all requests except requests for stati
1010
So, if you add the KnownUser validation logic to a central place, then be sure that the Triggers only fire on page requests (including ajax requests) and not on e.g. image.
1111

1212
The following is an example route in express/nodejs which shows how to validate that a user has been through the queue.
13-
It assumes that your integrationconfiguration file is located in root of the web application.
13+
It assumes that your integration configuration file is located in root of the web application.
1414

1515
```javascript
16+
const QUEUEIT_FAILED_HEADERNAME = "x-queueit-failed";
17+
const QUEUEIT_CONNECTOR_EXECUTED_HEADER_NAME = 'x-queueit-connector';
18+
const QUEUEIT_CONNECTOR_NAME = "nodejs"
19+
1620
var express = require('express');
1721
var router = express.Router();
1822
var fs = require('fs');
@@ -21,16 +25,29 @@ var QueueITConnector = require('queueit-knownuser');
2125

2226
configureKnownUserHashing();
2327

28+
function isIgnored(req){
29+
return req.method == 'HEAD' || req.method == 'OPTIONS'
30+
}
31+
2432
/* GET home page. */
2533
router.get('/', function (req, res, next) {
2634
try {
35+
res.header(QUEUEIT_CONNECTOR_EXECUTED_HEADER_NAME, QUEUEIT_CONNECTOR_NAME);
36+
if(isIgnored(req)){
37+
// Render page
38+
res.render('index', {
39+
node_version: process.version,
40+
express_version: require('express/package').version
41+
});
42+
return;
43+
}
2744
var integrationsConfigString = fs.readFileSync('integrationconfiguration.json', 'utf8');
2845

2946
var customerId = ""; // Your Queue-it customer ID
3047
var secretKey = ""; // Your 72 char secret key as specified in Go Queue-it self-service platform
3148

3249
var httpContextProvider = initializeExpressHttpContextProvider(req, res);
33-
50+
3451
var knownUser = QueueITConnector.KnownUser;
3552
var queueitToken = req.query[knownUser.QueueITTokenKey];
3653
var requestUrl = httpContextProvider.getHttpRequest().getAbsoluteUri();
@@ -85,6 +102,7 @@ router.get('/', function (req, res, next) {
85102
// Use your own logging framework to log the error
86103
// This was a configuration error, so we let the user continue
87104
console.log("ERROR:" + e);
105+
res.header(QUEUEIT_FAILED_HEADERNAME, 'true');
88106
}
89107
});
90108

@@ -124,12 +142,12 @@ function initializeExpressHttpContextProvider(req, res) {
124142
},
125143
getHttpResponse: function () {
126144
var httpResponse = {
127-
setCookie: function (cookieName, cookieValue, domain, expiration, httpOnly, isSecure, sameSiteValue) {
145+
setCookie: function (cookieName, cookieValue, domain, expiration, httpOnly, isSecure) {
128146
if (domain === "")
129147
domain = null;
130148

131149
// expiration is in secs, but Date needs it in milisecs
132-
var expirationDate = new Date(expiration * 1000);
150+
const expirationDate = new Date(expiration * 1000);
133151

134152
// This requires 'cookie-parser' node module (installed/used from app.js)
135153
res.cookie(
@@ -140,8 +158,7 @@ function initializeExpressHttpContextProvider(req, res) {
140158
path: "/",
141159
domain: domain,
142160
secure: isSecure,
143-
httpOnly: httpOnly,
144-
sameSite: sameSiteValue
161+
httpOnly: httpOnly
145162
});
146163
}
147164
};
@@ -172,6 +189,10 @@ Specify the configuration in code without using the Trigger/Action paradigm. In
172189
The following is an example (using Express/Nodejs) of how to specify the configuration in code:
173190

174191
```javascript
192+
const QUEUEIT_FAILED_HEADERNAME = "x-queueit-failed";
193+
const QUEUEIT_CONNECTOR_EXECUTED_HEADER_NAME = 'x-queueit-connector';
194+
const QUEUEIT_CONNECTOR_NAME = "nodejs"
195+
175196
var express = require('express');
176197
var router = express.Router();
177198
var fs = require('fs');
@@ -180,9 +201,23 @@ var QueueITConnector = require('queueit-knownuser');
180201

181202
configureKnownUserHashing();
182203

204+
function isIgnored(req){
205+
return req.method == 'HEAD' || req.method == 'OPTIONS'
206+
}
207+
183208
/* GET home page. */
184209
router.get('/', function (req, res, next) {
185210
try {
211+
res.header(QUEUEIT_CONNECTOR_EXECUTED_HEADER_NAME, QUEUEIT_CONNECTOR_NAME);
212+
if(isIgnored(req)){
213+
// Render page
214+
res.render('index', {
215+
node_version: process.version,
216+
express_version: require('express/package').version
217+
});
218+
return;
219+
}
220+
186221
var integrationsConfigString = fs.readFileSync('integrationconfiguration.json', 'utf8');
187222

188223
var customerId = ""; // Your Queue-it customer ID
@@ -253,6 +288,7 @@ router.get('/', function (req, res, next) {
253288
// Use your own logging framework to log the error
254289
// This was a configuration error, so we let the user continue
255290
console.log("ERROR:" + e);
291+
res.header(QUEUEIT_FAILED_HEADERNAME, 'true');
256292
}
257293
});
258294

dist/HttpContextProvider.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface IHttpRequest {
77
getRequestBodyAsString(): string;
88
}
99
export interface IHttpResponse {
10-
setCookie(cookieName: string, cookieValue: string, domain: string, expiration: number, httpOnly: boolean, isSecure: boolean, sameSiteValue: string): any;
10+
setCookie(cookieName: string, cookieValue: string, domain: string, expiration: number, httpOnly: boolean, isSecure: boolean): any;
1111
}
1212
export interface IHttpContextProvider {
1313
getHttpRequest(): IHttpRequest;

dist/IntegrationConfig/IntegrationConfigModel.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export declare class IntegrationConfigModel {
44
CookieDomain: string;
55
IsCookieHttpOnly: boolean;
66
IsCookieSecure: boolean;
7-
CookieSameSiteValue: string | null;
87
LayoutName: string;
98
Culture: string;
109
ExtendCookieValidity: boolean | null;

dist/IntegrationConfig/IntegrationConfigModel.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/KnownUser.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)