Json Web Tokens (JWT)

What are Json Web Tokens

Json Web Tokens, or JWT for short, are a standard way to carry verifiable identity information. This can be used for authentication. The advantage of using JWTs is that since they are a standard format and cryptographically signed, they can usually be verified without contacting an external authentication server. To support this use case, the application server verifying the JWTs needs to be setup with a private key for verification - JWTs signed by that key will be verified by the application server. Those who are not will be rejected (usually via an HTTP 401 response code).

JWTs are in use in various scenarios: - OpenID Connect’s id_token is a JWT. The id_token is used to identify the End User (Resource Owner in the OIDC\OAuth terminology) and is usually sent by the client (phone app or web-browser) to the cloud back-end (“Resource Server” in the OIDC\OAuth terminology) - Kubernetes uses JWT as service accounts secrets within Pods. A program running in a Pod can use this JWT to authenticate with the Kuberenetes API server with the permissions of the service account.

How is a JWT structured

A JWT has three parts: - The header - The payload - The signature

All three parts are combined with the “.” character to form the final token. The header has some metadata on the JWT (like the signing algorithm). The payload carries claims that the token makes (more on that in the next section). And finally the signature part is a cryptographic signature that signs the header and the payload.

How does a JWT Carry Identity Information

Inside the JWT various claims are encoded, that provide identity information. A few of standard claims are:

The claims are encoded as a JSON object, and then encoded with base64 to form the payload of the JWT

How is a JWT Verified

Most commonly asymmetric encryption is used to sign JWTs. To verify them a public key is used. This has the advantage of make verification easy - the public key can be distributed as it is not secret and cannot be used to sign new JWTs. The JWT can be independently verified by anyone using the public key.

JWTs in Gloo

Gloo supports JWT verification using the JWT extension. You can define multiple JWT providers. In each provider you can specify where to find the keys required for JWT verification, the values for the issuer and audience claims to verify, as well as other settings.

We have a few guides that go into more details: