queueit_knownuserv3 3.6.1 → 3.7.1
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.
- checksums.yaml +7 -0
- data/Gemfile +4 -4
- data/LICENSE +21 -0
- data/README.md +188 -0
- data/Rakefile +2 -2
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/lib/queueit_knownuserv3/connector_diagnostics.rb +68 -68
- data/lib/queueit_knownuserv3/httpcontext_provider.rb +93 -0
- data/lib/queueit_knownuserv3/integration_config_helpers.rb +297 -272
- data/lib/queueit_knownuserv3/known_user.rb +410 -399
- data/lib/queueit_knownuserv3/models.rb +138 -126
- data/lib/queueit_knownuserv3/queue_url_params.rb +80 -80
- data/lib/queueit_knownuserv3/user_in_queue_service.rb +168 -157
- data/lib/queueit_knownuserv3/user_in_queue_state_cookie_repository.rb +191 -191
- data/lib/queueit_knownuserv3.rb +11 -10
- data/queueit_knownuserv3.gemspec +28 -28
- metadata +10 -16
- data/.devcontainer/Dockerfile +0 -43
- data/.devcontainer/devcontainer.json +0 -30
- data/.gitignore +0 -5
- data/.vscode/launch.json +0 -15
- data/ci-build.yml +0 -17
- data/license.txt +0 -165
|
@@ -1,157 +1,168 @@
|
|
|
1
|
-
require 'open-uri'
|
|
2
|
-
require 'cgi'
|
|
3
|
-
|
|
4
|
-
module QueueIt
|
|
5
|
-
class UserInQueueService
|
|
6
|
-
SDK_VERSION_NO = "3.
|
|
7
|
-
SDK_VERSION = "v3-ruby-" + SDK_VERSION_NO
|
|
8
|
-
|
|
9
|
-
def initialize(userInQueueStateRepository)
|
|
10
|
-
@userInQueueStateRepository = userInQueueStateRepository
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def validateQueueRequest(targetUrl, queueitToken, config, customerId, secretKey)
|
|
14
|
-
state = @userInQueueStateRepository.getState(config.eventId, config.cookieValidityMinute, secretKey, true)
|
|
15
|
-
if (state.isValid)
|
|
16
|
-
if (state.isStateExtendable && config.extendCookieValidity)
|
|
17
|
-
@userInQueueStateRepository.store(
|
|
18
|
-
config.eventId,
|
|
19
|
-
state.queueId,
|
|
20
|
-
nil,
|
|
21
|
-
!Utils::isNilOrEmpty(config.cookieDomain) ? config.cookieDomain : '',
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
requestValidationResult =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId,
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def
|
|
92
|
-
query = getQueryString(customerId, config.eventId, config.version, config.actionName, config.culture, config.layoutName) +
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
1
|
+
require 'open-uri'
|
|
2
|
+
require 'cgi'
|
|
3
|
+
|
|
4
|
+
module QueueIt
|
|
5
|
+
class UserInQueueService
|
|
6
|
+
SDK_VERSION_NO = "3.7.1"
|
|
7
|
+
SDK_VERSION = "v3-ruby-" + SDK_VERSION_NO
|
|
8
|
+
|
|
9
|
+
def initialize(userInQueueStateRepository)
|
|
10
|
+
@userInQueueStateRepository = userInQueueStateRepository
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def validateQueueRequest(targetUrl, queueitToken, config, customerId, secretKey)
|
|
14
|
+
state = @userInQueueStateRepository.getState(config.eventId, config.cookieValidityMinute, secretKey, true)
|
|
15
|
+
if (state.isValid)
|
|
16
|
+
if (state.isStateExtendable && config.extendCookieValidity)
|
|
17
|
+
@userInQueueStateRepository.store(
|
|
18
|
+
config.eventId,
|
|
19
|
+
state.queueId,
|
|
20
|
+
nil,
|
|
21
|
+
!Utils::isNilOrEmpty(config.cookieDomain) ? config.cookieDomain : '',
|
|
22
|
+
config.isCookieHttpOnly,
|
|
23
|
+
config.isCookieSecure,
|
|
24
|
+
state.redirectType,
|
|
25
|
+
secretKey)
|
|
26
|
+
end
|
|
27
|
+
return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, state.queueId, nil, state.redirectType, config.actionName)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
queueParams = QueueUrlParams::extractQueueParams(queueitToken)
|
|
31
|
+
|
|
32
|
+
requestValidationResult = nil
|
|
33
|
+
isTokenValid = false
|
|
34
|
+
|
|
35
|
+
if (!queueParams.nil?)
|
|
36
|
+
tokenValidationResult = validateToken(config, queueParams, secretKey)
|
|
37
|
+
isTokenValid = tokenValidationResult.isValid
|
|
38
|
+
|
|
39
|
+
if (isTokenValid)
|
|
40
|
+
requestValidationResult = getValidTokenResult(config, queueParams, secretKey)
|
|
41
|
+
else
|
|
42
|
+
requestValidationResult = getErrorResult(customerId, targetUrl, config, queueParams, tokenValidationResult.errorCode)
|
|
43
|
+
end
|
|
44
|
+
else
|
|
45
|
+
requestValidationResult = getQueueResult(targetUrl, config, customerId)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
if (state.isFound && !isTokenValid)
|
|
49
|
+
@userInQueueStateRepository.cancelQueueCookie(config.eventId, config.cookieDomain, config.isCookieHttpOnly, config.isCookieSecure);
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
return requestValidationResult;
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey)
|
|
56
|
+
state = @userInQueueStateRepository.getState(cancelConfig.eventId, -1, secretKey, false)
|
|
57
|
+
if (state.isValid)
|
|
58
|
+
@userInQueueStateRepository.cancelQueueCookie(cancelConfig.eventId, cancelConfig.cookieDomain, cancelConfig.isCookieHttpOnly, cancelConfig.isCookieSecure)
|
|
59
|
+
|
|
60
|
+
query = getQueryString(customerId, cancelConfig.eventId, cancelConfig.version, cancelConfig.actionName, nil, nil) +
|
|
61
|
+
(!Utils::isNilOrEmpty(targetUrl) ? ("&r=" + Utils.urlEncode(targetUrl)) : "" )
|
|
62
|
+
|
|
63
|
+
uriPath = "cancel/" + customerId + "/" + cancelConfig.eventId
|
|
64
|
+
|
|
65
|
+
if(!Utils::isNilOrEmpty(state.queueId))
|
|
66
|
+
uriPath = uriPath + "/" + state.queueId
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
redirectUrl = generateRedirectUrl(cancelConfig.queueDomain, uriPath, query)
|
|
70
|
+
|
|
71
|
+
return RequestValidationResult.new(ActionTypes::CANCEL, cancelConfig.eventId, state.queueId, redirectUrl, state.redirectType, cancelConfig.actionName)
|
|
72
|
+
else
|
|
73
|
+
return RequestValidationResult.new(ActionTypes::CANCEL, cancelConfig.eventId, nil, nil, nil, cancelConfig.actionName)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def getValidTokenResult(config, queueParams, secretKey)
|
|
78
|
+
@userInQueueStateRepository.store(
|
|
79
|
+
config.eventId,
|
|
80
|
+
queueParams.queueId,
|
|
81
|
+
queueParams.cookieValidityMinutes,
|
|
82
|
+
!Utils::isNilOrEmpty(config.cookieDomain) ? config.cookieDomain : '',
|
|
83
|
+
config.isCookieHttpOnly,
|
|
84
|
+
config.isCookieSecure,
|
|
85
|
+
queueParams.redirectType,
|
|
86
|
+
secretKey)
|
|
87
|
+
|
|
88
|
+
return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, queueParams.queueId, nil, queueParams.redirectType, config.actionName)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def getErrorResult(customerId, targetUrl, config, qParams, errorCode)
|
|
92
|
+
query = getQueryString(customerId, config.eventId, config.version, config.actionName, config.culture, config.layoutName) +
|
|
93
|
+
"&queueittoken=" + qParams.queueITToken +
|
|
94
|
+
"&ts=" + Time.now.getutc.tv_sec.to_s +
|
|
95
|
+
(!Utils::isNilOrEmpty(targetUrl) ? ("&t=" + Utils.urlEncode(targetUrl)) : "")
|
|
96
|
+
|
|
97
|
+
redirectUrl = generateRedirectUrl(config.queueDomain, "error/" + errorCode + "/", query)
|
|
98
|
+
|
|
99
|
+
return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, nil, redirectUrl, nil, config.actionName)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def getQueueResult(targetUrl, config, customerId)
|
|
103
|
+
query = getQueryString(customerId, config.eventId, config.version, config.actionName, config.culture, config.layoutName) +
|
|
104
|
+
(!Utils::isNilOrEmpty(targetUrl) ? "&t=" + Utils.urlEncode( targetUrl) : "")
|
|
105
|
+
|
|
106
|
+
redirectUrl = generateRedirectUrl(config.queueDomain, "", query)
|
|
107
|
+
|
|
108
|
+
return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, nil, redirectUrl, nil, config.actionName)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def getQueryString(customerId, eventId, configVersion, actionName, culture, layoutName)
|
|
112
|
+
queryStringList = Array.new
|
|
113
|
+
queryStringList.push("c=" + Utils.urlEncode(customerId))
|
|
114
|
+
queryStringList.push("e=" + Utils.urlEncode(eventId))
|
|
115
|
+
queryStringList.push("ver=" + SDK_VERSION)
|
|
116
|
+
queryStringList.push("cver=" + (!configVersion.nil? ? configVersion.to_s : '-1'))
|
|
117
|
+
queryStringList.push("man=" + Utils.urlEncode(actionName))
|
|
118
|
+
|
|
119
|
+
if (!Utils::isNilOrEmpty(culture))
|
|
120
|
+
queryStringList.push("cid=" + Utils.urlEncode(culture))
|
|
121
|
+
end
|
|
122
|
+
if (!Utils::isNilOrEmpty(layoutName))
|
|
123
|
+
queryStringList.push("l=" + Utils.urlEncode(layoutName))
|
|
124
|
+
end
|
|
125
|
+
return queryStringList.join("&")
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def generateRedirectUrl(queueDomain, uriPath, query)
|
|
129
|
+
if (!queueDomain.end_with?("/") )
|
|
130
|
+
queueDomain = queueDomain + "/"
|
|
131
|
+
end
|
|
132
|
+
return "https://" + queueDomain + uriPath + "?" + query
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def extendQueueCookie(eventId, cookieValidityMinutes, cookieDomain, isCookieHttpOnly, isCookieSecure, secretKey)
|
|
136
|
+
@userInQueueStateRepository.reissueQueueCookie(eventId, cookieValidityMinutes, cookieDomain, isCookieHttpOnly, isCookieSecure, secretKey)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def getIgnoreActionResult(actionName)
|
|
140
|
+
return RequestValidationResult.new(ActionTypes::IGNORE, nil, nil, nil, nil, actionName)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def validateToken(config, queueParams, secretKey)
|
|
144
|
+
calculatedHash = OpenSSL::HMAC.hexdigest('sha256', secretKey, queueParams.queueITTokenWithoutHash)
|
|
145
|
+
if (calculatedHash.upcase() != queueParams.hashCode.upcase())
|
|
146
|
+
return TokenValidationResult.new(false, "hash")
|
|
147
|
+
end
|
|
148
|
+
if (queueParams.eventId.upcase() != config.eventId.upcase())
|
|
149
|
+
return TokenValidationResult.new(false, "eventid")
|
|
150
|
+
end
|
|
151
|
+
if (queueParams.timeStamp < Time.now.getutc.tv_sec)
|
|
152
|
+
return TokenValidationResult.new(false, "timestamp")
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
return TokenValidationResult.new(true, nil)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
class TokenValidationResult
|
|
159
|
+
attr_reader :isValid
|
|
160
|
+
attr_reader :errorCode
|
|
161
|
+
|
|
162
|
+
def initialize(isValid, errorCode)
|
|
163
|
+
@isValid = isValid
|
|
164
|
+
@errorCode = errorCode
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|