Home Assistant Unofficial Reference 2024.12.1
homeassistant.auth.jwt_wrapper Namespace Reference

Classes

class  _PyJWSWithLoadCache
 
class  _PyJWTWithVerify
 

Functions

dict[str, Any] _decode_payload (str json_payload)
 

Variables

list __all__
 
 _jws = _PyJWSWithLoadCache()
 
 _jwt = _PyJWTWithVerify()
 
dictionary _NO_VERIFY_OPTIONS = {f"verify_{key}": False for key in _VERIFY_KEYS}
 
tuple _VERIFY_KEYS = ("signature", "exp", "nbf", "iat", "aud", "iss", "sub", "jti")
 
int JWT_TOKEN_CACHE_SIZE = 16
 
int MAX_TOKEN_SIZE = 8192
 
 unverified_hs256_token_decode
 
 verify_and_decode = _jwt.verify_and_decode
 

Detailed Description

Provide a wrapper around JWT that caches decoding tokens.

Since we decode the same tokens over and over again
we can cache the result of the decode of valid tokens
to speed up the process.

Function Documentation

◆ _decode_payload()

dict[str, Any] homeassistant.auth.jwt_wrapper._decode_payload ( str  json_payload)
private
Decode the payload from a JWS dictionary.

Definition at line 45 of file jwt_wrapper.py.

Variable Documentation

◆ __all__

list homeassistant.auth.jwt_wrapper.__all__
private
Initial value:
1 = [
2  "unverified_hs256_token_decode",
3  "verify_and_decode",
4 ]

Definition at line 114 of file jwt_wrapper.py.

◆ _jws

homeassistant.auth.jwt_wrapper._jws = _PyJWSWithLoadCache()
private

Definition at line 41 of file jwt_wrapper.py.

◆ _jwt

homeassistant.auth.jwt_wrapper._jwt = _PyJWTWithVerify()
private

Definition at line 106 of file jwt_wrapper.py.

◆ _NO_VERIFY_OPTIONS

dictionary homeassistant.auth.jwt_wrapper._NO_VERIFY_OPTIONS = {f"verify_{key}": False for key in _VERIFY_KEYS}
private

Definition at line 26 of file jwt_wrapper.py.

◆ _VERIFY_KEYS

tuple homeassistant.auth.jwt_wrapper._VERIFY_KEYS = ("signature", "exp", "nbf", "iat", "aud", "iss", "sub", "jti")
private

Definition at line 21 of file jwt_wrapper.py.

◆ JWT_TOKEN_CACHE_SIZE

int homeassistant.auth.jwt_wrapper.JWT_TOKEN_CACHE_SIZE = 16

Definition at line 18 of file jwt_wrapper.py.

◆ MAX_TOKEN_SIZE

int homeassistant.auth.jwt_wrapper.MAX_TOKEN_SIZE = 8192

Definition at line 19 of file jwt_wrapper.py.

◆ unverified_hs256_token_decode

homeassistant.auth.jwt_wrapper.unverified_hs256_token_decode
Initial value:
1 = lru_cache(maxsize=JWT_TOKEN_CACHE_SIZE)(
2  partial(
3  _jwt.decode_payload, key="", algorithms=["HS256"], options=_NO_VERIFY_OPTIONS
4  )
5 )

Definition at line 108 of file jwt_wrapper.py.

◆ verify_and_decode

homeassistant.auth.jwt_wrapper.verify_and_decode = _jwt.verify_and_decode

Definition at line 107 of file jwt_wrapper.py.