Skip to content

Commit 5c01a4d

Browse files
committed
release v.3.7
1 parent 7dfa310 commit 5c01a4d

11 files changed

Lines changed: 203 additions & 123 deletions

Examples/Apache/ApacheHandlerUsingConfigFromFile.lua

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
--... * QUEUEIT_INT_CONF_FILE: The local JSON file containing the integration configuration
1515
-- * QUEUEIT_ERROR_CODE: (optional) The response code to use instead of declining to act
1616
-- if request handling fails
17-
-- * QUEUEIT_COOKIE_OPTIONS_HTTPONLY: (optional) Set to "true" if you want cookies with httponly
18-
-- flag set. Only enable if this you use pure server-side integration
19-
-- e.g. not JS Hybrid.
20-
-- * QUEUEIT_COOKIE_OPTIONS_SECURE: (optional) Set to "true" if you want cookies with secure
21-
-- flag set. Only enable if your website runs purely on https.
2217
-- Note that the integration configuration is read on every request. The JSON file containing
2318
-- The integration configuration should, for performance reasons, be available locally.
2419
--
@@ -29,6 +24,7 @@
2924
-- SetEnv QUEUEIT_CUSTOMER_ID "{CUSTOMER_ID}"
3025
-- SetEnv QUEUEIT_SECRET_KEY "{SECRET_KEY}"
3126
-- SetEnv QUEUEIT_INT_CONF_FILE "{APP_FOLDER}/integration_config.json"
27+
-- SetEnv QUEUEIT_ERROR_CODE "400"
3228
-- LuaMapHandler "{URI_PATTERN}" "{APP_FOLDER}/Handlers/ApacheHandlerUsingConfigFromFile.lua"
3329
-- LuaPackagePath "{APP_FOLDER}/SDK/?.lua"
3430
-- LuaPackagePath "{APP_FOLDER}/Helpers/?/?.lua"
@@ -45,7 +41,7 @@ local DEBUG_TAG = "ApacheHandlerUsingConfigFromFile.lua"
4541
local kuHandler = require("KnownUserApacheHandler")
4642
local file = require("file")
4743

48-
local function initRequiredHelpers(r, cookieOptions)
44+
local function initRequiredHelpers(r)
4945
local iHelpers = require("KnownUserImplementationHelpers")
5046

5147
iHelpers.request.getAbsoluteUri = function()
@@ -56,8 +52,6 @@ local function initRequiredHelpers(r, cookieOptions)
5652
r:debug(string.format("[%s] Rebuilt request URL as: %s", DEBUG_TAG, fullUrl))
5753
return fullUrl
5854
end
59-
60-
iHelpers.response.cookieOptions = cookieOptions
6155
end
6256

6357
function handle(r)
@@ -73,8 +67,6 @@ function handle(r)
7367
local secretKey = r.subprocess_env["QUEUEIT_SECRET_KEY"]
7468
local intConfFile = r.subprocess_env["QUEUEIT_INT_CONF_FILE"]
7569
local errorCode = r.subprocess_env["QUEUEIT_ERROR_CODE"]
76-
local co_httpOnly = r.subprocess_env["QUEUEIT_COOKIE_OPTIONS_HTTPONLY"]
77-
local co_secure = r.subprocess_env["QUEUEIT_COOKIE_OPTIONS_SECURE"]
7870

7971
if customerId ~= nil then
8072
r:debug(string.format("[%s] Environment variable QUEUEIT_CUSTOMER_ID: %s", DEBUG_TAG, customerId))
@@ -88,12 +80,6 @@ function handle(r)
8880
if errorCode ~= nil then
8981
r:debug(string.format("[%s] Environment variable QUEUEIT_ERROR_CODE: %s", DEBUG_TAG, errorCode))
9082
end
91-
if co_httpOnly ~= nil then
92-
r:debug(string.format("[%s] Environment variable QUEUEIT_COOKIE_OPTIONS_HTTPONLY: %s", DEBUG_TAG, co_httpOnly))
93-
end
94-
if co_secure ~= nil then
95-
r:debug(string.format("[%s] Environment variable QUEUEIT_COOKIE_OPTIONS_SECURE: %s", DEBUG_TAG, co_secure))
96-
end
9783

9884
assert(customerId ~= nil, "customerId invalid")
9985
assert(secretKey ~= nil, "secretKey invalid")
@@ -112,18 +98,8 @@ function handle(r)
11298
end
11399
r:debug(string.format("[%s] Value of variable errorCode: %s", DEBUG_TAG, errorCode))
114100

115-
-- configure cookie options
116-
local cookieOptions =
117-
{
118-
httpOnly = false,
119-
secure = false
120-
}
121-
122-
if (co_httpOnly ~= nil and co_httpOnly == 'true') then cookieOptions.httpOnly = true end
123-
if (co_secure ~= nil and co_secure == 'true') then cookieOptions.secure = true end
124-
125101
-- initialize helper functions
126-
initRequiredHelpers(r, cookieOptions)
102+
initRequiredHelpers(r)
127103

128104
-- read integration configuration from file
129105
local intConfJson = file.readAll(intConfFile)

Handlers/KnownUserApacheHandler.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
103103
-- Implementation is not using built in r:setcookie method
104104
-- because we want to support Apache version < 2.4.12
105105
-- where there is bug in that specific method
106-
iHelpers.response.setCookie = function(name, value, expire, domain)
106+
iHelpers.response.setCookie = function(name, value, expire, domain, isHttpOnly, isSecure)
107107
-- lua_mod only supports 1 Set-Cookie header (because 'err_headers_out' is a table).
108108
-- So calling this method (setCookie) multiple times will not work as expected.
109109
-- In this case final call will apply.
@@ -126,8 +126,8 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
126126
request_rec.err_headers_out["Set-Cookie"] = name .. '=' .. value
127127
.. expire_text
128128
.. (domain ~= "" and '; Domain=' .. domain or '')
129-
.. (iHelpers.response.cookieOptions.httpOnly and '; HttpOnly' or '')
130-
.. (iHelpers.response.cookieOptions.secure and '; Secure' or '')
129+
.. (isHttpOnly and '; HttpOnly' or '')
130+
.. (isSecure and '; Secure' or '')
131131
.. '; Path=/;'
132132

133133
end
@@ -153,7 +153,9 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
153153
-- end
154154

155155
if (validationResult.isAjaxResult) then
156-
request_rec.err_headers_out[validationResult.getAjaxQueueRedirectHeaderKey()] = validationResult:getAjaxRedirectUrl()
156+
local headerName = validationResult.getAjaxQueueRedirectHeaderKey()
157+
request_rec.err_headers_out[headerName] = validationResult:getAjaxRedirectUrl()
158+
request_rec.err_headers_out['Access-Control-Expose-Headers'] = headerName
157159
else
158160
request_rec.err_headers_out["Location"] = validationResult.redirectUrl
159161
return apache2.HTTP_MOVED_TEMPORARILY

Handlers/KnownUserNginxHandler.lua

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ iHelpers.request.getUserHostAddress = function()
3939
return ngx.var.remote_addr
4040
end
4141

42-
iHelpers.response.setCookie = function(name, value, expire, domain)
42+
iHelpers.response.setCookie = function(name, value, expire, domain, isHttpOnly, isSecure)
4343
-- lua_mod only supports 1 Set-Cookie header (because 'header' is a table).
4444
-- So calling this method (setCookie) multiple times will not work as expected.
4545
-- In this case final call will apply.
@@ -62,8 +62,8 @@ iHelpers.response.setCookie = function(name, value, expire, domain)
6262
ngx.header["Set-Cookie"] = name .. '=' .. value
6363
.. expire_text
6464
.. (domain ~= "" and '; Domain=' .. domain or '')
65-
.. (iHelpers.response.cookieOptions.httpOnly and '; HttpOnly' or '')
66-
.. (iHelpers.response.cookieOptions.secure and '; Secure' or '')
65+
.. (isHttpOnly and '; HttpOnly' or '')
66+
.. (isSecure and '; Secure' or '')
6767
.. '; Path=/;'
6868
end
6969

@@ -73,24 +73,6 @@ end
7373

7474
local aHandler = {}
7575

76-
aHandler.setOptions = function(options)
77-
if (options == nil) then
78-
error('invalid options')
79-
end
80-
81-
if (options.secure) then
82-
iHelpers.response.cookieOptions.secure = true
83-
else
84-
iHelpers.response.cookieOptions.secure = false
85-
end
86-
87-
if (options.httpOnly) then
88-
iHelpers.response.cookieOptions.httpOnly = true
89-
else
90-
iHelpers.response.cookieOptions.httpOnly = false
91-
end
92-
end
93-
9476
aHandler.handleByIntegrationConfig = function(customerId, secretKey, integrationConfigJson)
9577
local queueitToken = ''
9678
if (ngx.var.arg_queueittoken ~= nil) then
@@ -111,7 +93,9 @@ aHandler.handleByIntegrationConfig = function(customerId, secretKey, integration
11193
-- end
11294

11395
if (validationResult.isAjaxResult) then
114-
ngx.header[validationResult.getAjaxQueueRedirectHeaderKey()] = validationResult:getAjaxRedirectUrl()
96+
local headerName = validationResult.getAjaxQueueRedirectHeaderKey()
97+
ngx.header[headerName] = validationResult:getAjaxRedirectUrl()
98+
ngx.header['Access-Control-Expose-Headers'] = headerName
11599
else
116100
ngx.redirect(validationResult.redirectUrl)
117101
ngx.exit(ngx.HTTP_MOVED_TEMPORARILY)

SDK/KnownUser.lua

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ local function setDebugCookie(debugEntries)
3737
cookieValue = cookieValue .. (key .. "=" .. value .. "|")
3838
end
3939
cookieValue = cookieValue:sub(0, cookieValue:len()-1) -- remove trailing |
40-
iHelpers.response.setCookie(QUEUEIT_DEBUG_KEY, cookieValue, 0, nil)
40+
iHelpers.response.setCookie(QUEUEIT_DEBUG_KEY, cookieValue, 0, nil, false, false)
4141
end
4242

4343
local function generateTargetUrl(originalTargetUrl)
@@ -124,7 +124,8 @@ local function cancelRequestByLocalConfig(
124124
end
125125
-- END Private functions
126126

127-
ku.extendQueueCookie = function(eventId, cookieValidityMinute, cookieDomain, secretKey)
127+
ku.extendQueueCookie = function(
128+
eventId, cookieValidityMinute, cookieDomain, isCookieHttpOnly, isCookieSecure, secretKey)
128129
assert(utils.toString(eventId) ~= "", "eventId can not be nil or empty.")
129130
assert(utils.toString(secretKey) ~= "", "secretKey can not be nil or empty.")
130131

@@ -133,7 +134,8 @@ ku.extendQueueCookie = function(eventId, cookieValidityMinute, cookieDomain, sec
133134
error("cookieValidityMinute should be a number greater than 0.")
134135
end
135136

136-
userInQueueService.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey)
137+
userInQueueService.extendQueueCookie(
138+
eventId, cookieValidityMinute, cookieDomain, isCookieHttpOnly, isCookieSecure, secretKey)
137139
end
138140

139141
ku.cancelRequestByLocalConfig = function(targetUrl, queueitToken, cancelConfig, customerId, secretKey)
@@ -165,19 +167,27 @@ ku.validateRequestByIntegrationConfig = function(
165167
currentUrlWithoutQueueITToken, queueitToken, integrationConfigJson, customerId, secretKey)
166168
-- Private functions
167169
local function handleQueueAction(
168-
_currentUrlWithoutQueueITToken, _queueitToken, _customerIntegration,
169-
_customerId, _secretKey, _matchedConfig, _debugEntries, _isDebug)
170+
_currentUrlWithoutQueueITToken,
171+
_queueitToken,
172+
_customerIntegration,
173+
_customerId,
174+
_secretKey,
175+
_matchedConfig,
176+
_debugEntries,
177+
_isDebug)
170178

171179
local eventConfig = models.QueueEventConfig.create()
172180
local targetUrl
173181
eventConfig.eventId = _matchedConfig["EventId"]
182+
eventConfig.version = _customerIntegration["Version"]
174183
eventConfig.queueDomain = _matchedConfig["QueueDomain"]
175-
eventConfig.layoutName = _matchedConfig["LayoutName"]
176-
eventConfig.culture = _matchedConfig["Culture"]
177184
eventConfig.cookieDomain = _matchedConfig["CookieDomain"]
185+
eventConfig.isCookieHttpOnly = _matchedConfig["IsCookieHttpOnly"] or false
186+
eventConfig.isCookieSecure = _matchedConfig["IsCookieSecure"] or false
178187
eventConfig.extendCookieValidity = _matchedConfig["ExtendCookieValidity"]
179188
eventConfig.cookieValidityMinute = _matchedConfig["CookieValidityMinute"]
180-
eventConfig.version = _customerIntegration["Version"]
189+
eventConfig.layoutName = _matchedConfig["LayoutName"]
190+
eventConfig.culture = _matchedConfig["Culture"]
181191
eventConfig.actionName = _matchedConfig["Name"]
182192

183193
if (_matchedConfig["RedirectLogic"] == "ForcedTargetUrl"
@@ -201,9 +211,11 @@ ku.validateRequestByIntegrationConfig = function(
201211

202212
local cancelEventConfig = models.CancelEventConfig.create()
203213
cancelEventConfig.eventId = _matchedConfig["EventId"]
214+
cancelEventConfig.version = _customerIntegration["Version"]
204215
cancelEventConfig.queueDomain = _matchedConfig["QueueDomain"]
205216
cancelEventConfig.cookieDomain = _matchedConfig["CookieDomain"]
206-
cancelEventConfig.version = _customerIntegration["Version"]
217+
cancelEventConfig.isCookieHttpOnly = _matchedConfig["IsCookieHttpOnly"] or false
218+
cancelEventConfig.isCookieSecure = _matchedConfig["IsCookieSecure"] or false
207219
cancelEventConfig.actionName = _matchedConfig["Name"]
208220

209221
return cancelRequestByLocalConfig(

SDK/KnownUserImplementationHelpers.lua

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,14 @@ local iHelpers =
3535
{
3636
cookieOptions =
3737
{
38-
-- true if response cookies should have httponly flag set
39-
-- only enable if you use pure server-side integration e.g. not JS Hybrid
40-
httpOnly = false,
41-
-- true if response cookies should have secure flag set
42-
-- only enable if your website runs on https
43-
secure = false,
4438
-- set to any string value (none, strict, lax) if response cookies should have samesite flag set
4539
-- only use 'strict' if your queue protected site stays on same domain (no navigation to subdomains)
4640
sameSite = nil
4741
},
48-
-- arguments: name, value, expire, domain
42+
-- arguments: name, value, expire, domain, isHttpOnly, isSecure
4943
-- returns: void
50-
setCookie = function(_, _, _, _)
51-
error("Not implemented : response.setCookie(name, value, expire, domain)")
44+
setCookie = function(_, _, _, _, _, _)
45+
error("Not implemented : response.setCookie(name, value, expire, domain, isHttpOnly, isSecure)")
5246
end
5347
},
5448
hash =

SDK/Models.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ local models = {
1111
extendCookieValidity = nil,
1212
cookieValidityMinute = nil,
1313
cookieDomain = nil,
14+
isCookieHttpOnly = nil,
15+
isCookieSecure = nil,
1416
version = nil,
1517
actionName = "unspecified",
1618
getString = function(self)
@@ -19,6 +21,8 @@ local models = {
1921
"&Version:" .. utils.toString(self.version) ..
2022
"&QueueDomain:" .. utils.toString(self.queueDomain) ..
2123
"&CookieDomain:" .. utils.toString(self.cookieDomain) ..
24+
"&IsCookieHttpOnly:" .. utils.toString(self.isCookieHttpOnly) ..
25+
"&IsCookieSecure:" .. utils.toString(self.isCookieSecure) ..
2226
"&ExtendCookieValidity:" .. utils.toString(self.extendCookieValidity) ..
2327
"&CookieValidityMinute:" .. utils.toString(self.cookieValidityMinute) ..
2428
"&LayoutName:" .. utils.toString(self.layoutName) ..
@@ -36,6 +40,8 @@ local models = {
3640
eventId = nil,
3741
queueDomain = nil,
3842
cookieDomain = nil,
43+
isCookieHttpOnly = nil,
44+
isCookieSecure = nil,
3945
version = nil,
4046
actionName = "unspecified",
4147
getString = function(self)
@@ -44,6 +50,8 @@ local models = {
4450
"&Version:" .. utils.toString(self.version) ..
4551
"&QueueDomain:" .. utils.toString(self.queueDomain) ..
4652
"&CookieDomain:" .. utils.toString(self.cookieDomain) ..
53+
"&IsCookieHttpOnly:" .. utils.toString(self.isCookieHttpOnly) ..
54+
"&IsCookieSecure:" .. utils.toString(self.isCookieSecure) ..
4755
"&ActionName:" .. utils.toString(self.actionName)
4856
end
4957
}

0 commit comments

Comments
 (0)