Hi
I’m working on a custom plugin that takes a plain username/password from our frontend, authenticates it, generates a JWT token, and sends it downstream. It works fine but for some URLs (callbacks from services we use) I need to skip this and authenticate it on the backend, not via authentication service.
this is what I’m trying to do
local request_path = kong.request.get_path()
local callback_path = conf.callback_path
local is_callback = request_path:sub(1, #callback_path) == callback_path
if is_callback then
-- keep the authorization header
return kong.response.exit(200, "{}", {
["Authorization"] = authorizationHeader
})
end
but there are two problems here:
-
tests are failing because some headers are missing (
./spec/helpers.lua:938: Could not determine the response to be from mock_upstream
) -
I’m just sending the header but I need the whole request to be passed downstream (headers, body, etc)
I also tried to send the raw body and all headers in the response.exit
like below
return kong.response.exit(200, kong.request.get_raw_body(), kong.request.get_headers())
but got another error
./spec/helpers.lua:932: Expected the http response object to have a json encoded body, but decoding gave error 'Expected value but found T_END at character 1'. Obtained body:
.The assertion 'request' modifier takes a http response object as input to decode the json-body returned by mock_upstream, to retrieve the proxied request
basically what I need is something like this:
if is_callback then
send_it_all_downstream
stop_plugin_execution
end
I read through the plugin dev. kit docs but I couldn’t find a way to do what I want.
Does anyone know how to do it? Any help is much appreciated