How to add multiple access_by_lua_file directive under same location = /_sample

2.4k Views Asked by At

Using openidc module introspection under location and calling using below,

 Policy section
#
location = /_sample {
    internal;
    set $api_name "sample"; 
    access_by_lua_file /etc/nginx/path/oauth_introspection.lua;
     Proxypass......
}

Now i want to include below lua file to add some contents and validate something under the same request.

 Policy section
#
location = /_sample {
    internal;
    set $api_name "sample"; 
    access_by_lua_file /etc/nginx/path/oauth_introspection.lua;
        access_by_lua_file /etc/nginx/path/do_something.lua; //Error with duplicate
     Proxypass......
}

And my oauth_introspection.lua has this openidc introspect logic,

local res, err = require("resty.openidc").introspect(opts)
1

There are 1 best solutions below

0
On

access_by_lua_file can be used only once. You must combine your code in lua file:

location = /_sample {
    internal;
    set $api_name "sample"; 
    access_by_lua_file /etc/nginx/path/action_sample.lua;
    Proxypass......
}

action_sample.lua:

local res, err = require("resty.openidc").introspect(opts)

-- do something or 
loadfile("/etc/nginx/path/do_something.lua")(opts)