Kong to call api for authentication of requests

How to customize kong to call api for authentication of requests. Based on the response code received from the api call, give UNAUTHORIZED error to the client or forward the request to the upstream server


To achieve this, you would need to write your own plugin, in Lua. The best resource to start is the Plugin Development Guide, which will elaborate on plugins architecture, and how to write them. Another useful resource since Kong 0.14 is the introduction of the Plugin Development Kit (PDK), which provides you with helper functions to manipulate the request/response from a plugin.

There are many examples of plugins making HTTP requests from Kong (e.g. the AWS Lambda plugin).

Have fun!

Thanks a lot for the resources. I have started writing my own plugin.
I am new to lua and I am getting an error

luajit: …ocal/opt/kong/share/lua/5.1/kong/plugins/base_plugin.lua:4: attempt to index global ‘ngx’ (a nil value)

when i am trying to write
local BasePlugin = require "kong.plugins.base_plugin"
in the handler.lua file.

Can you please tell me some resource which I could refer for setting up the complete environment for building kong plugin. I am using MacOS

Hello, did you finished writing your plugin? I’m interested as well in this way of handling authentication