pyauthorizer.encryptor package

pyauthorizer.encryptor.get_encryptor(target)[source]

Get the encryptor corresponding to the target.

Parameters:

target (str) – The target for which to retrieve the encryptor.

Returns:

An instance of the encryptor class corresponding to the target, or None if no encryptor is found.

Return type:

BaseEncryptor | None

Subpackages

Submodules

pyauthorizer.encryptor.base module

class pyauthorizer.encryptor.base.BaseEncryptor[source]

Bases: ABC

Abstract base class for encryptors.

abstract decrypt(token)[source]

Decrypts the provided token.

Parameters:

token (Token) – The token to decrypt.

Returns:

A dictionary containing the decrypted data.

Return type:

dict

abstract encrypt(data)[source]

Encrypts the provided data.

Parameters:

data (dict) – The data to be encrypted.

Returns:

A tuple containing the secret key and the encrypted token.

Return type:

Tuple[str, str]

generate_token(data)[source]

Generates a token based on the provided data.

Parameters:

data (dict) – The data to be used for generating the token.

Returns:

The generated token.

Return type:

Token

validate_token(token, data)[source]

Validates a token by comparing its decrypted data with the provided data dictionary.

Parameters:
  • token (Token) – The token object to be validated.

  • data (dict) – The dictionary containing the data to be matched with the token’s decrypted data.

Returns:

The status of the token after validation. Possible values are:
  • TokenStatus.INVALID: If the token data does not match the provided data dictionary.

  • TokenStatus.ACTIVE: If the token is valid and active.

  • TokenStatus.EXPIRED: If the token is valid but has expired.

Return type:

TokenStatus

class pyauthorizer.encryptor.base.Token(secret_key, token, expiry)[source]

Bases: object

Class representing a token.

Parameters:
  • secret_key (str) – The secret key associated with the token.

  • token (str) – The token value.

  • expiry (str) – The expiry date of the token.

expiry: str
secret_key: str
token: str
class pyauthorizer.encryptor.base.TokenStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum representing the status of a token.

ACTIVE = 1

Token is valid and active.

EXPIRED = 2

Token is valid but has expired.

INVALID = 3

Token is invalid.

pyauthorizer.encryptor.interface module

pyauthorizer.encryptor.interface.get_encryptor(target)[source]

Get the encryptor corresponding to the target.

Parameters:

target (str) – The target for which to retrieve the encryptor.

Returns:

An instance of the encryptor class corresponding to the target, or None if no encryptor is found.

Return type:

BaseEncryptor | None

pyauthorizer.encryptor.plugin_manager module

class pyauthorizer.encryptor.plugin_manager.EncryptorPlugins[source]

Bases: PluginManager

Plugin manager for encryptor plugins

class pyauthorizer.encryptor.plugin_manager.PluginManager(group_name)[source]

Bases: ABC

Base class for managing plugins

Parameters:

group_name (str) – The name of the plugin group.

property has_registered: bool

Check if plugins have been registered

register(flavor_name, plugin_module)[source]

Register a plugin.

Parameters:
  • flavor_name (str) – The name of the flavor.

  • plugin_module (str) – The name of the plugin module.

Return type:

None

Returns:

None

register_entrypoints()[source]

Register plugins using entrypoints

Return type:

None

property registry: dict[str, EntryPoint]

Get the plugin registry

pyauthorizer.encryptor.utils module

pyauthorizer.encryptor.utils.decrypt_with_cipher(token, cipher)[source]

Decrypts a token using the provided cipher and returns the decrypted token data.

Parameters:
Returns:

The decrypted token data as a dictionary.

Return type:

dict[str, Any]

pyauthorizer.encryptor.utils.generate_key()[source]

Generate a key using the Fernet encryption algorithm.

Returns:

A randomly generated key.

Return type:

bytes

pyauthorizer.encryptor.utils.get_id_on_mac()[source]

Get the MAC address of the machine.

Return type:

str