RFC7517: JSON Web Key

This section contains the generic implementation of RFC7517. Find how to use it in JWK Guide.

API Reference

class authlib.jose.JsonWebKey
classmethod generate_key(kty, crv_or_size, options=None, is_private=False)

Generate a Key with the given key type, curve name or bit size.

Parameters:
  • kty – string of oct, RSA, EC, OKP

  • crv_or_size – curve name or bit size

  • options – a dict of other options for Key

  • is_private – create a private key or public key

Returns:

Key instance

classmethod import_key(raw, options=None)

Import a Key from bytes, string, PEM or dict.

Returns:

Key instance

classmethod import_key_set(raw)

Import KeySet from string, dict or a list of keys.

Returns:

KeySet instance

class authlib.jose.Key(options=None)

This is the base class for a JSON Web Key.

check_key_op(operation)

Check if the given key_op is supported by this key.

Parameters:

operation – key operation value, such as “sign”, “encrypt”.

Raise:

ValueError

as_json(is_private=False, **params)

Represent this key as a JSON string.

thumbprint()

Implementation of RFC7638 JSON Web Key (JWK) Thumbprint.

class authlib.jose.KeySet(keys)

This class represents a JSON Web Key Set.

as_dict(is_private=False, **params)

Represent this key as a dict of the JSON Web Key Set.

as_json(is_private=False, **params)

Represent this key set as a JSON string.

find_by_kid(kid)

Find the key matches the given kid value.

Parameters:

kid – A string of kid

Returns:

Key instance

Raise:

ValueError

class authlib.jose.OctKey(raw_key=None, options=None)

Key class of the oct key type.

get_op_key(operation)

Get the raw key for the given key_op. This method will also check if the given key_op is supported by this key.

Parameters:

operation – key operation value, such as “sign”, “encrypt”.

Returns:

raw key

classmethod import_key(raw, options=None)

Import a key from bytes, string, or dict data.

classmethod generate_key(key_size=256, options=None, is_private=True)

Generate a OctKey with the given bit size.

class authlib.jose.RSAKey(private_key=None, public_key=None, options=None)

Key class of the RSA key type.

PUBLIC_KEY_CLS

alias of RSAPublicKey

PRIVATE_KEY_CLS

alias of RSAPrivateKey

class authlib.jose.ECKey(private_key=None, public_key=None, options=None)

Key class of the EC key type.

PUBLIC_KEY_CLS

alias of EllipticCurvePublicKey

PRIVATE_KEY_CLS

alias of EllipticCurvePrivateKey