Skip to content

JWKS

JSON Web Key Set operations per RFC 7517.

Key Models

JsonWebKey(kty, use=None, key_ops=None, alg=None, kid=None, x5u=None, x5c=None, x5t=None, x5t_s256=None, crv=None, x=None, y=None, d=None, n=None, e=None, p=None, q=None, dp=None, dq=None, qi=None, oth=None, k=None) dataclass

A JSON Web Key (JWK) as defined in RFC 7517. The 'kty' (key type) parameter is required for all key types. Other parameters are required based on the key type.

has_private_key property

Check if the key contains private key parts

key_size property

Calculate the key size in bits

__post_init__()

Validate the JWK after initialization

from_json(json_str) classmethod

Create a JWK from a JSON string

to_json()

Convert the JWK to a JSON string

as_dict()

Convert the JWK to a dictionary with all available properties

JsonWebKeyParameterNames

Bases: Enum

Parameter names as defined in RFC 7517

__str__()

Return the string value of the enum

JsonWebAlgorithmsKeyTypes

Bases: Enum

Request / Response Models

JwksRequest(address) dataclass

Bases: BaseRequest

Request for fetching a JSON Web Key Set.

Attributes:

Name Type Description
address str

The JWKS endpoint URL (typically from DiscoveryDocumentResponse.jwks_uri).

JwksResponse(is_successful, error=None, keys=None) dataclass

Bases: BaseResponse

Response from a JWKS endpoint fetch.

Check is_successful before accessing keys.

Sync API

get_jwks(jwks_request, http_client=None)

Fetch JWKS from the specified address.

Parameters:

Name Type Description Default
jwks_request JwksRequest

JWKS request configuration

required
http_client HTTPClient | None

Optional managed HTTP client. When None, uses the thread-local default.

None

Returns:

Name Type Description
JwksResponse JwksResponse

JWKS response with keys

jwks_from_dict(keys_dict)

Parse a JWKS dictionary into a JsonWebKey object.

Parameters:

Name Type Description Default
keys_dict dict

Dictionary containing JWK parameters

required

Returns:

Name Type Description
JsonWebKey JsonWebKey

Parsed JWK object

Async API

get_jwks(jwks_request, http_client=None) async

Fetch JWKS from the specified address (async).

Parameters:

Name Type Description Default
jwks_request JwksRequest

JWKS request configuration

required
http_client AsyncHTTPClient | None

Optional managed HTTP client. When None, uses the module-level singleton.

None

Returns:

Name Type Description
JwksResponse JwksResponse

JWKS response with keys