How to rewrite JWT Plugin response


If the jwt Unauthorized. It will response

{ “message”: “Unauthorized”}

I want rewrite the response like this:

{“status”: 401, “message”: “Unauthorized”}

I use the response-transfer plugin. but it not work.

curl -X POST http://localhost:8001/plugins
–data “name=response-transformer”
–data “consumer_id=88805b30-427c-4b34-bd71-666674e1ae17”
–data “config.add.json=status:401”

How can I do?



The response-transformer plugin will try to add status: "404" to all the responses that go through Kong, not just the failed ones. It is not possible to “only execute the transformation in certain occasions”.

I think the best way to do what you want is modifying the source code of the JWT plugin on your installation to make it return the request like you want it, and then reload Kong.