RFC7515: JSON Web Signature

This section contains the generic implementation of RFC7515. Find how to use it in JWS Guide.

API Reference

authlib.jose.rfc7515.JWS

alias of authlib.jose.rfc7515.jws.JsonWebSignature

class authlib.jose.rfc7515.JWSHeader(protected, header)

Header object for JWS. It combine the protected header and unprotected header together. JWSHeader itself is a dict of the combined dict. e.g.

>>> protected = {'alg': 'HS256'}
>>> header = {'kid': 'a'}
>>> jws_header = JWSHeader(protected, header)
>>> print(jws_header)
{'alg': 'HS256', 'kid': 'a'}
>>> jws_header.protected == protected
>>> jws_header.header == header
Parameters:
  • protected – dict of protected header
  • header – dict of unprotected header
class authlib.jose.rfc7515.JWSObject(header, payload, type='compact')

A dict instance to represent a JWS object.

class authlib.jose.rfc7515.JWSAlgorithm

Interface for JWS algorithm. JWA specification (RFC7518) SHOULD implement the algorithms for JWS with this base implementation.

prepare_private_key(key)

Prepare key for sign signature.

prepare_public_key(key)

Prepare key for verify signature.

sign(msg, key)

Sign the text msg with a private/sign key.

Parameters:
  • msg – message bytes to be signed
  • key – private key to sign the message
Returns:

bytes

verify(msg, key, sig)

Verify the signature of text msg with a public/verify key.

Parameters:
  • msg – message bytes to be signed
  • key – public key to verify the signature
  • sig – result signature to be compared
Returns:

boolean