Skip to content

jam.jose.lists.json

json

Classes:

Name Description
JSONList

JSON file-based JWT black/white list.

JSONList

JSONList(
    type: Literal["white", "black"],
    prefix: str = "jwt_list",
    json_path: str = "whitelist.json",
    logger: BaseLogger | None = None,
)

Bases: BaseJWTList

JSON file-based JWT black/white list.

Not recommended for blacklists - no TTL support, user must manage token lifetime.

Dependency required: pip install jamlib[json]

Attributes:

Name Type Description
_db TinyDB

TinyDB instance.

_prefix str

Key prefix.

Methods:

Name Description
add

add single token to list

add_many

add multiple tokens to list

check

check if token exists in list

check_many

check multiple tokens in list

delete

remove token from list

delete_many

remove multiple tokens from list

Parameters:

Name Type Description Default
type Literal['white', 'black']

Type of list.

required
prefix str

Key prefix (used for logging).

'jwt_list'
json_path str

Path to JSON file.

'whitelist.json'
logger BaseLogger | None

Logger instance.

None

add

add(token: str) -> None

Add a single token to the list.

Parameters:

Name Type Description Default
token str

JWT token.

required

add_many

add_many(tokens: list[str]) -> None

Add multiple tokens to the list.

Parameters:

Name Type Description Default
tokens list[str]

List of JWT tokens.

required

check

check(token: str) -> bool

Check if a token is present in the list.

Parameters:

Name Type Description Default
token str

JWT token.

required

Returns:

Name Type Description
bool bool

True if token exists in list.

check_many

check_many(tokens: list[str]) -> dict[str, bool]

Check multiple tokens in the list.

Parameters:

Name Type Description Default
tokens list[str]

List of JWT tokens.

required

Returns:

Type Description
dict[str, bool]

dict[str, bool]: Mapping of token to presence.

delete

delete(token: str) -> None

Remove a token from the list.

Parameters:

Name Type Description Default
token str

JWT token.

required

delete_many

delete_many(tokens: list[str]) -> None

Remove multiple tokens from the list.

Parameters:

Name Type Description Default
tokens list[str]

List of JWT tokens.

required