I'm trying to modify a lua file provided from 3scale. I keep getting the following error:
runtime error: /etc/nginx/nginx.lua:361: attempt to concatenate field 'user_id' (a nil value)
And the block of code that leads to this error is:
local params = {}
local host = ngx.req.get_headers()["Host"]
local auth_strat = ""
local service = {}
if ngx.var.service_id == 'ID' then
local parameters = get_auth_params("not_headers", string.split(ngx.var.request, " ")[1] )
service = service_ID --
ngx.var.secret_token = service.secret_token
params.user_id = parameters.user_id
-- Get access token from response
params.access_token = parameters.access_token
ngx.var.access_token = params.access_token .. ":" .. params.user_id
get_credentials_access_token(params, service_ID)
ngx.var.cached_key = "ID" .. ":" .. params.access_token
auth_strat = "oauth"
ngx.var.service_id = "ID"
ngx.var.proxy_pass = "http://backend_api.mysite.com"
ngx.var.usage = extract_usage_ID(ngx.var.request)
end
If I place ngx.var.access_token = params.access_token .. ":" .. params.user_id
after get_credentials_access_token(params, service_ID)
the error doesn't occur. What could be leading to this behavior?
EDIT:
The original file can be found at https://github.com/3scale/nginx-oauth-templates/blob/master/oauth2/implicit-flow/token-generation/nginx.lua