@@ -46,19 +46,19 @@ router.get('/', function (req, res, next) {
4646 var customerId = " " ; // Your Queue-it customer ID
4747 var secretKey = " " ; // Your 72 char secret key as specified in Go Queue-it self-service platform
4848
49- var httpContextProvider = initializeExpressHttpContextProvider (req, res);
49+ var contextProvider = initializeExpressContextProvider (req, res);
5050
5151 var knownUser = QueueITConnector .KnownUser ;
5252 var queueitToken = req .query [knownUser .QueueITTokenKey ];
53- var requestUrl = httpContextProvider .getHttpRequest ().getAbsoluteUri ();
53+ var requestUrl = contextProvider .getHttpRequest ().getAbsoluteUri ();
5454 var requestUrlWithoutToken = getRequestUrlWithoutToken (requestUrl);
5555 // The requestUrlWithoutToken is used to match Triggers and as the Target url (where to return the users to).
5656 // It is therefor important that this is exactly the url of the users browsers. So, if your webserver is
5757 // behind e.g. a load balancer that modifies the host name or port, reformat requestUrlWithoutToken before proceeding.
5858
5959 var validationResult = knownUser .validateRequestByIntegrationConfig (
6060 requestUrlWithoutToken, queueitToken, integrationsConfigString,
61- customerId, secretKey, httpContextProvider );
61+ customerId, secretKey, contextProvider );
6262
6363 if (validationResult .doRedirect ()) {
6464 // Adding no cache headers to prevent browsers to cache requests
@@ -126,11 +126,31 @@ function getRequestUrlWithoutToken(requestUrl){
126126module .exports = router;
127127```
128128
129- Code to initialize a httpContextProvider in Express (requires node module 'cookie-parser'):
129+ Code to initialize a contextProvider in Express (requires node module 'cookie-parser'):
130130
131131``` javascript
132- function initializeExpressHttpContextProvider (req , res ) {
132+ function initializeExpressContextProvider (req , res ) {
133133 return {
134+ getCryptoProvider : function () {
135+ // Code to configure hashing in KnownUser SDK (requires node module 'crypto'):
136+ return {
137+ getSha256Hash : function (secretKey , plaintext ) {
138+ const crypto = require (' crypto' );
139+ const hash = crypto .createHmac (' sha256' , secretKey)
140+ .update (plaintext)
141+ .digest (' hex' );
142+ return hash;
143+ }
144+ };
145+ },
146+ getEnqueueTokenProvider : function (){
147+ return {
148+ getEnqueueToken : function (){
149+ // If you need to use an enqueue token when enqueuing, you need to return it here.
150+ return null ;
151+ }
152+ };
153+ },
134154 getHttpRequest : function () {
135155 var httpRequest = {
136156 getUserAgent : function () {
@@ -185,21 +205,6 @@ function initializeExpressHttpContextProvider(req, res) {
185205}
186206```
187207
188- Code to configure hashing in KnownUser SDK (requires node module 'crypto'):
189-
190- ``` javascript
191- function configureKnownUserHashing () {
192- var utils = QueueITConnector .Utils ;
193- utils .generateSHA256Hash = function (secretKey , stringToHash ) {
194- const crypto = require (' crypto' );
195- const hash = crypto .createHmac (' sha256' , secretKey)
196- .update (stringToHash)
197- .digest (' hex' );
198- return hash;
199- };
200- }
201- ```
202-
203208## Implementation using inline queue configuration
204209Specify the configuration in code without using the Trigger/Action paradigm. In this case it is important * only to queue-up page requests* and not requests for resources or AJAX calls. This can be done by adding custom filtering logic before caling the ` knownUser.resolveQueueRequestByLocalConfig() ` method.
205210
@@ -216,8 +221,6 @@ var fs = require('fs');
216221
217222var QueueITConnector = require (' queueit-knownuser' );
218223
219- configureKnownUserHashing ();
220-
221224function isIgnored (req ){
222225 return req .method == ' HEAD' || req .method == ' OPTIONS'
223226}
@@ -249,19 +252,19 @@ router.get('/', function (req, res, next) {
249252 // queueConfig.culture = "da-DK" // Optional - Culture of the queue layout in the format specified here: https://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx. If unspecified then settings from Event will be used.
250253 // queueConfig.layoutName = "NameOfYourCustomLayout" // Optional - Name of the queue layout. If unspecified then settings from Event will be used.
251254
252- var httpContextProvider = initializeExpressHttpContextProvider (req, res);
255+ var contextProvider = initializeExpressContextProvider (req, res);
253256
254257 var knownUser = QueueITConnector .KnownUser ;
255258 var queueitToken = req .query [knownUser .QueueITTokenKey ];
256- var requestUrl = httpContextProvider .getHttpRequest ().getAbsoluteUri ();
259+ var requestUrl = contextProvider .getHttpRequest ().getAbsoluteUri ();
257260 var requestUrlWithoutToken = getRequestUrlWithoutToken (requestUrl);
258261 // The requestUrlWithoutToken is used to match Triggers and as the Target url (where to return the users to).
259262 // It is therefor important that this is exactly the url of the users browsers. So, if your webserver is
260263 // behind e.g. a load balancer that modifies the host name or port, reformat requestUrlWithoutToken before proceeding.
261264
262265 var validationResult = knownUser .resolveQueueRequestByLocalConfig (
263266 requestUrlWithoutToken, queueitToken, queueConfig,
264- customerId, secretKey, httpContextProvider );
267+ customerId, secretKey, contextProvider );
265268
266269 if (validationResult .doRedirect ()) {
267270 // Adding no cache headers to prevent browsers to cache requests
@@ -348,6 +351,9 @@ app.use(bodyParser.text());
348351And then add this to the httpRequest object in your http context provider:
349352``` javascript
350353getRequestBodyAsString : function () {
354+ if (! req .body || ! req .body .toString ){
355+ return " " ;
356+ }
351357 return JSON .stringify (req .body .toString ());
352358}
353359```
0 commit comments