[go: up one dir, main page]

Skip to content

This Kong API Gateway Plugin can be used to route requests by JWT claim. It does this by converting JWT claims to headers during rewrite phase so that Kong's route by header functionality can be used to route the request appropriately. Alternatively, the plugin can be used to simply convert JWT claims to headers that can be consumed by the upstream

License

Notifications You must be signed in to change notification settings

ken20082006/kong-jwt2header

 
 

Repository files navigation

Kong Plugin: JWT To Header

This is a kong plugin for extract claims from JWT to the header.

Installation

pack the plugin

With luarocks(3.9.2) and lua(>5.1)

execute the below command

luarocks make kong-jwt2header-1.0-1.rockspec
luarocks pack kong-jwt2header 1.0-1

use Docker

This repo contain a lua container for you to pack the plugin yourself. Follow the below step:

Start the container:

docker compose up -d

Pack the plugin using the container:

docker exec -it [CONTAINER_NAME] luarocks make kong-jwt2header-1.0-1.rockspec
docker exec -it [CONTAINER_NAME] luarocks pack kong-jwt2header 1.0-1

docker cp [CONTAINER_NAME]:/tmp/volume/kong-jwt2header-1.0-1.all.rock kong-jwt2header-1.0-1.all.rock

You will have the packed plugin file kong-jwt2header-1.0-1.all.rock

luarocks

Verify Git is installed on your Kong Node then install via luarocks:

$ luarocks install kong-plugin-jwt2header-1.0-1.all.rock

Once installed, besure to include kong-jwt2header in your KONG_PLUGINS environment variable and reload Kong.

Using the plugin

curl -X POST http://localhost:8001/services/{serviceName|Id}/plugins \
    --data "name=kong-jwt2header"  \
    --data "config.claims=sub,aud"

After added the plugin, new headers with prefix X-Kong-JWT-Claim- will be added. ie. X-Kong-JWT-Claim-sub and X-Kong-JWT-Claim-aud

Configuration

Since this plugin has elements that must run in the Rewrite execution phase, this plugin can only be configured to run globally in a kong workspace or cluster.

Parameter Default Description Required
claims The claims that you want to add to header, comma separated yes

About

This Kong API Gateway Plugin can be used to route requests by JWT claim. It does this by converting JWT claims to headers during rewrite phase so that Kong's route by header functionality can be used to route the request appropriately. Alternatively, the plugin can be used to simply convert JWT claims to headers that can be consumed by the upstream

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 100.0%