oneid.jose

Utility functions for dealing with JOSE objects generally.

Mostly used internally, but may be useful for external callers.

oneid.jose.is_compact_jws(msg)[source]

Determine if a given message is a compact JWS (or JWT) or not. Does not necessarily mean that it is valid or authentic.

Parameters:msg (str) – message to inspect
Returns:True if the message is a compact JWS, False otherwise
Return type:bool
oneid.jose.is_jws(msg, json_decoder=<function loads>)[source]

Determine if a given message is a JWS or not (compact or otherwise). Does not necessarily mean that it is valid or authentic.

Parameters:
  • msg (str or dict) – message to inspect
  • json_decoder – a function to decode JSON into a dict. Defaults to json.loads
Returns:

True if the message is a JWS, False otherwise

Return type:

bool

oneid.jose.is_jwe(msg, json_decoder=<function loads>)[source]

Determine if a given message is a JWE or not. Does not necessarily mean that it is valid or authentic.

Parameters:
  • msg (str or dict) – message to inspect
  • json_decoder – a function to decode JSON into a dict. Defaults to json.loads
Returns:

True if the message is a JWS, False otherwise

Return type:

bool

oneid.jose.get_jwe_shared_header(jwe, json_decoder=<function loads>)[source]

Extract shared (non-encrypted) header values from a JWE

Parameters:
  • jwe (str or dict) – JWE to extract header field values from
  • json_decoder – a function to decode JSON into a dict. Defaults to json.loads
Returns:

header fields and values

Return type:

dict

Raises:

InvalidFormatError: if not a valid JWE

oneid.jose.normalize_claims(raw_claims, issuer=None)[source]

Return a set of claims based on the provided claim set that includes reasonable defaults for required claims.

Note that the claims may be in the form of a valid JWE, in which case the inner values may be inspected.

Parameters:
  • raw_claims (dict) – Initial set of claims, may or may not include required claims
  • issuer – (optional) identifier of the identity creating the message
Returns:

filled-out claims

Return type:

dict

oneid.jose.as_dict(msg, json_decoder=<function loads>)[source]

Unpack a message (if necessary) into its dictionary form.

Parameters:
  • msg (str or dict) – message to convert
  • json_decoder – a function to decode JSON into a dict. Defaults to json.loads
Returns:

the message in dictionary form

Return type:

dict