@@ -186,12 +186,11 @@ function _M:extractContextVars(profile)
186
186
return cachingObj
187
187
end
188
188
189
- function _M :validateRequest ()
189
+ function _M :validateUserProfile ()
190
190
-- ngx.var.authtoken needs to be set before calling this method
191
191
local oauth_token = ngx .var .authtoken
192
192
if oauth_token == nil or oauth_token == " " then
193
- -- return self:exitFn(ngx.HTTP_BAD_REQUEST)
194
- return self :exitFn (RESPONSES .P_MISSING_TOKEN .error_code , cjson .encode (RESPONSES .P_MISSING_TOKEN ))
193
+ return RESPONSES .P_MISSING_TOKEN .error_code , cjson .encode (RESPONSES .P_MISSING_TOKEN )
195
194
end
196
195
197
196
-- 1. try to get user's profile from the cache first ( local or redis cache )
@@ -205,9 +204,9 @@ function _M:validateRequest()
205
204
end
206
205
self :setContextProperties (self :getContextPropertiesObject (cachedUserProfile ))
207
206
if ( self :isProfileValid (cachedUserProfile ) == true ) then
208
- return self : exitFn ( ngx .HTTP_OK )
207
+ return ngx .HTTP_OK
209
208
else
210
- return self : exitFn ( RESPONSES .INVALID_PROFILE .error_code , cjson .encode (RESPONSES .INVALID_PROFILE ) )
209
+ return RESPONSES .INVALID_PROFILE .error_code , cjson .encode (RESPONSES .INVALID_PROFILE )
211
210
end
212
211
end
213
212
@@ -223,9 +222,9 @@ function _M:validateRequest()
223
222
self :storeProfileInCache (cacheLookupKey , cachingObj )
224
223
225
224
if ( self :isProfileValid (cachingObj ) == true ) then
226
- return self : exitFn ( ngx .HTTP_OK )
225
+ return ngx .HTTP_OK
227
226
else
228
- return self : exitFn ( RESPONSES .INVALID_PROFILE .error_code , cjson .encode (RESPONSES .INVALID_PROFILE ) )
227
+ return RESPONSES .INVALID_PROFILE .error_code , cjson .encode (RESPONSES .INVALID_PROFILE )
229
228
end
230
229
else
231
230
ngx .log (ngx .WARN , " Could not decode /validate-user response:" .. tostring (res .body ) )
@@ -234,11 +233,15 @@ function _M:validateRequest()
234
233
-- ngx.log(ngx.WARN, "Could not read /ims-profile. status=" .. res.status .. ".body=" .. res.body .. ". token=" .. ngx.var.authtoken)
235
234
ngx .log (ngx .WARN , " Could not read /validate-user. status=" .. res .status .. " .body=" .. res .body )
236
235
if ( res .status == ngx .HTTP_UNAUTHORIZED or res .status == ngx .HTTP_BAD_REQUEST ) then
237
- return self : exitFn ( RESPONSES .NOT_ALLOWED .error_code , cjson .encode (RESPONSES .NOT_ALLOWED ) )
236
+ return RESPONSES .NOT_ALLOWED .error_code , cjson .encode (RESPONSES .NOT_ALLOWED )
238
237
end
239
238
end
240
239
-- ngx.log(ngx.WARN, "Error validating Profile for Token:" .. tostring(ngx.var.authtoken))
241
- return self :exitFn (RESPONSES .P_UNKNOWN_ERROR .error_code , cjson .encode (RESPONSES .P_UNKNOWN_ERROR ))
240
+ return RESPONSES .P_UNKNOWN_ERROR .error_code , cjson .encode (RESPONSES .P_UNKNOWN_ERROR )
241
+ end
242
+
243
+ function _M :validateRequest ()
244
+ return self :exitFn (self :validateUserProfile ())
242
245
end
243
246
244
247
return _M
0 commit comments