adafruit_jwt

JSON Web Token Authentication

  • Author(s): Brent Rubell

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_jwt.JWT

JSON Web Token helper for CircuitPython. Warning: JWTs are credentials, which can grant access to resources. Be careful where you paste them!

Parameters:

algo (str) – Encryption algorithm used for claims. Can be None.

static generate(claims: dict, private_key_data: Tuple[int, int, int, int, int] | None = None, algo: str | None = None, headers: dict | None = None) str

Generates and returns a new JSON Web Token.

Parameters:
  • claims (dict) – JWT claims set

  • private_key_data (tuple) – Decoded RSA private key data.

  • algo (str) – algorithm to be used. One of None, RS256, RS384 or RS512.

  • headers (dict) – additional headers for the claim.

Return type:

str

static validate(jwt: str) Tuple[str, dict]

Validates a provided JWT. Does not support validating nested signing. Returns JOSE Header and claim set.

Parameters:

jwt (str) – JSON Web Token.

Returns:

The message’s decoded JOSE header and claims.

Return type:

tuple

class adafruit_jwt.STRING_TOOLS

Tools and helpers for URL-safe string encoding.

static translate(s: str, table: dict) str

Return a copy of the string in which each character has been mapped through the given translation table.

Parameters:
  • s (string) – String to-be-character-table.

  • table (dict) – Translation table.

static urlsafe_b64decode(payload: array | bytearray | bytes | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray | str) str

Decode bytes-like object or ASCII string using the URL and filesystem-safe alphabet

Parameters:

payload (bytes) – bytes-like object or ASCII string

static urlsafe_b64encode(payload: array | bytearray | bytes | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray) str

Encode bytes-like object using the URL- and filesystem-safe alphabet, which substitutes - instead of + and _ instead of / in the standard Base64 alphabet, and return the encoded bytes.

Parameters:

payload (bytes) – bytes-like object.