# How to Craft and Sign a Custom JWT in Kong Konnect
Jerome Guillaume
The JSON Web Token (JWT) is an open standard that allows information to be transferred securely between different parties. The token is digitally signed by using a private key (HMAC) or a public/private key (RSA) by building a JSON Web Signature (JWS). It guarantees that the JWT hasn’t been modified since its creation.
The main benefits of a JWT are:
- authentication, like SSO and avoid session management
- authorization giving access to certain resources
- securely exchange information in a compact form
Here are the main use cases in which the Kong Gateway should craft and sign a custom JWT:
- Due to legacy, some Consumers still use API Key or Basic Authentication. At the same time, the backend APIs (requested by those Consumers) can require a JWT as input to embrace new standards and have a higher level of security. So the plugin is used to convert the API Key or Basic authentication to a modern JWT token authentication
- Do like a token exchange: get the Consumer JWT token and craft a new JWT that can then be used to access protected resources. This pattern can be used, for instance, for BFF (Backend for Frontend) and avoid using the same token throughout the call chain to transmit the identity of the caller
The structure of a JWT is based on three parts separated by a dot: header.payload.signature
- header: there is at least the token type (JWT) and the signing algorithm (HMAC or RSA)
- payload: there is information, called claims, for instance, the client_id.
- signature: calculated by encoding the header and payload and signed by the algorithm specified in the header
## Overview of the plugin mechanism
We propose the x-custom-jwt custom plugin for covering the use cases mentioned above. The mechanism of the plugin is:
- Craft a custom JWT using the input Authentication properties
- Load the private JWK from the plugin's configuration and convert it into a PEM format
- Sign the JWT with the PEM string for building a JWS (RS256 algorithm)
- Add the custom JWT to an HTTP Request Header backend API
The x-custom-jwt plugin doesn't check the validity of the Consumer’s authentication itself (it also doesn't check JWT signature & JWT expiration, user/password checking, Client TLS checking, or API key checking). So it's mandatory to use this plugin in conjunction with one of Kong's security plugins.
Depending on the enabled security plugin, the x-custom-jwt.client_id value varies:
- OIDC/JWT: client_id=clientId (default input claim and configurable)
- Basic Auth: client_id=UserName
- mTLS: client_id=subjectDN
- Key Auth: client_id=ApiKey
The backend API verifies the new JWT by downloading the public JWKS (JSON Web Key Sets) delivered by a Kong route and a Request Termination plugin. The JWKS is configured in x-custom-jwt.jku
## How to deploy the x-custom-jwt plugin in Konnect
Konnect is a hybrid architecture based on a Control Plane (for managing the configuration) and on Data Planes (aka the proxy gateway, for managing the API traffic) offering isolation for better security and performance.
Deploying a custom plugin requires updating the Control Plane and Data Planes:
- The Control Plane is updated by receiving the schema.lua which holds the schema of its configuration and defines rules on it so that the user can only enter valid configuration values
- The Data Planes need to be updated with the new custom plugin logic that we have defined. We can do this either by creating a custom image in Docker with our code or creating a configmap in the Kubernetes cluster and pointing Kong to that configmap on startup
**3. **If everything works correctly the jwt.io sends a Signature Verified message. The public key is downloaded automatically through the /x-custom-jwt-jwks route and the Request Termination plugin. If that's not the case, open the Browser Developer Tools and see the network tab and console tab. Otherwise, put in jwt.io this [jwk](https://github.com/Kong/kong-plugin-x-custom-jwt/blob/main/test-keys/RS256-jwk-public.json)jwk content in the signature Public Key field.
A common use case that is frequently requested is how to dynamically route requests based on authentication attributes. An example of this technique is routing requests to relevant upstream services based on claims contained in a JWT token. Admins w
Two of the best (in my opinion) features in Konnect are the ServiceHub and Dev Portal. However, they're also two of the most misunderstood. Aren't they the same thing? Why would you need a ServiceHub vs. Dev Portal? Well, I'm glad you asked! The r
Want to learn more about the nuts and bolts of APIOps? Download our eBook, Unlocking the Full Potential of your APIs with APIOps , and learn about the stages of APIOps, get an understanding of the technical assets required, and explore the tooling
As you build and maintain more applications, your authentication strategy becomes increasingly important. It may also be top of mind for your boss since technology leaders cited "improve application security" as one of their top priorities in this y
Architecture Overview
A multicloud DCGW architecture typically contains three main layers.
1\. Konnect Control Plane
The SaaS control plane manages configuration, plugins, and policies. All gateways connect securely to this layer.
2\. Dedicated C
Tool discovery for AI agents
In early agent implementations, tools are often statically configured inside the agent.
For example:
{
"mcpServers": {
"weatherServer": {
"command": "uv",
"args":
"run",
"weather_serv
In today's digital landscape, APIs are the backbone of modern applications, and AI is the engine of innovation. As organizations increasingly rely on microservices and AI-powered features, the API gateway has become the critical control point for man