JWKS and Key Types¶
This page covers GuardPost's JWKS (JSON Web Key Sets) API, including:
-
KeyTypeenum - The
JWKdataclass - The
JWKSdataclass — parsing and updating -
InMemoryKeysProvider -
URLKeysProvider -
AuthorityKeysProvider -
CachingKeysProvider— TTL and automatic refresh - Supported EC curves
KeyType enum¶
KeyType enumerates the supported key types:
| Value | Description |
|---|---|
KeyType.RSA |
RSA keys (used with RS256, RS384, RS512) |
KeyType.EC |
Elliptic Curve keys (used with ES256, ES384, ES512) |
KeyType.OCT |
Octet sequence / symmetric keys (used with HS256, HS384, HS512) |
KeyType.OKP |
Octet Key Pair (e.g. Ed25519) |
The JWK dataclass¶
JWK represents a single JSON Web Key. The fields depend on the key type:
| Field | Key type | Description |
|---|---|---|
kty |
all | Key type string ("RSA", "EC", "oct") |
pem |
all | The key material as PEM-encoded bytes |
kid |
optional | Key ID |
n |
RSA | Base64url-encoded modulus |
e |
RSA | Base64url-encoded public exponent |
crv |
EC | Curve name ("P-256", "P-384", "P-521") |
x |
EC | Base64url-encoded x coordinate |
y |
EC | Base64url-encoded y coordinate |
Parsing from a dict¶
Building RSA and EC PEMs from raw parameters¶
GuardPost exposes helper functions for building PEM-encoded keys from raw base64url parameters — useful when you receive individual key parameters instead of a full JWKS document.
The JWKS dataclass¶
JWKS represents a complete JSON Web Key Set — a collection of JWK objects.
Parsing from a dict¶
Updating a key set¶
JWKS.update(new_set) merges the keys from another JWKS into the current
one, replacing existing keys that share the same kid.
InMemoryKeysProvider¶
InMemoryKeysProvider wraps a static JWKS object. Use it in tests or when
you pre-load keys from configuration.
URLKeysProvider¶
URLKeysProvider fetches a JWKS document from a URL on demand. Use it when
your identity provider exposes a dedicated JWKS endpoint without an OpenID
Connect discovery document.
AuthorityKeysProvider¶
AuthorityKeysProvider uses OpenID Connect discovery to locate the JWKS URI
automatically. Provide the issuer URL and it will fetch
<authority>/.well-known/openid-configuration, parse the jwks_uri field,
and retrieve the key set from there.
Shorthand
Passing authority="..." to AsymmetricJWTValidator automatically creates
an AuthorityKeysProvider internally. You only need to create one manually
if you want to compose it with CachingKeysProvider.
CachingKeysProvider¶
CachingKeysProvider wraps any other KeysProvider and adds TTL-based
caching. This avoids hammering the JWKS endpoint on every token validation.
Key features:
- Keys are cached for
cache_timeseconds after each fetch. - When the cache age exceeds
cache_time - refresh_time, a background refresh is triggered proactively. - If a token's
kidis not found in the cached set, the cache is bypassed and the JWKS endpoint is queried immediately, supporting seamless key rotation.
Default caching
When you use the authority or keys_url shorthand on AsymmetricJWTValidator,
caching is set up automatically with the cache_time and refresh_time
parameters you provide (defaulting to 10800 s and 120 s respectively).
Supported EC curves¶
| Curve | JWT algorithm | Description |
|---|---|---|
P-256 |
ES256 |
256-bit NIST curve (most common) |
P-384 |
ES384 |
384-bit NIST curve |
P-521 |
ES512 |
521-bit NIST curve |
Last modified on: 2026-03-10 20:06:58