JSON Web Key Set (JWKS)
When creating applications and resources servers (APIs) in Auth0, two algorithms are supported for signing JSON Web Tokens (JWTs): RS256 and HS256. RS256 generates an asymmetric signature, which means a private key must be used to sign the JWT and a different public key must be used to verify the signature.
Auth0 uses the JWK specification to represent the cryptographic keys used for signing RS256 tokens. This specification defines two high level data structures: JSON Web Key (JWK) and JSON Web Key Set (JWKS). Here are the definitions directly from the specification:
JSON Web Key (JWK)
A JSON object that represents a cryptographic key. The members of the object represent properties of the key, including its value.
JSON Web Key Set (JWKS)
A JSON object that represents a set of JWKs. The JSON object MUST have a
keysmember, which is an array of JWKs.
At the most basic level, the JWKS is a set of keys containing the public keys that should be used to verify any JWT issued by the authorization server. Auth0 exposes a JWKS endpoint for each tenant, which is found at
https://YOUR_AUTH0_DOMAIN/.well-known/jwks.json. This endpoint will contain the JWK used to sign all Auth0 issued JWTs for this tenant.
This is an example of the JWKS used by a demo tenant.
The example JWKS above contains a single key. Each property in the key is defined by the JWK specification RFC 7517 Section 4. We will use these properties to determine which key was used to sign the JWT. Here is a quick breakdown of what each property represents:
- alg: is the algorithm for the key
- kty: is the key type
- use: is how the key was meant to be used. For the example above sig represents signature.
- x5c: is the x509 certificate chain
- e: is the exponent for a standard pem
- n: is the modulus for a standard pem
- kid: is the unique identifier for the key
- x5t: is the thumbprint of the x.509 cert (SHA-1 thumbprint)
Verifying a JWT using the JWKS endpoint
When verifying a JWT using a JWKS, here are the high level steps you will need to follow:
- Retrieve the JWKS and filter for potential signing keys.
- Extract the JWT from the request's authorization header.
- Decode the JWT and grab the
kidproperty from the header.
- Find the signing key in the filtered JWKS with a matching
- Using the
x5cproperty build a certificate which will be used to verify the JWT signature.
Using the JWKS in your application to verify a JWT
Due to the fact that there are such a wide range of technologies being used by our customers, going into detail of the actual implementation of verifying a JWT using a JWKS is beyond the scope of this document.
However, here are some resources which will assist you:
- When building an API, our Backend / API Quickstarts show how to implement signature verification for many different platforms. This is typically done by some form of middleware which is available on the particular platform.
- To manually verify a token's signature, you can use one of the libraries listed in the Libraries for Token Signing/Verification section of JWT.io. Refer to the documentation of the relevant library for the exact implementation details.
- Our blog post Navigating RS256 and JWKS shows a sample implementation using Node.js.