示例#1
0
from cryptography.hazmat.primitives.serialization import load_pem_private_key
from cryptography.hazmat.primitives.serialization import load_pem_public_key

import jwt
from jwt import InvalidSignatureError, ExpiredSignatureError, DecodeError

from hopeit.app.context import EventContext
from hopeit.server.config import AuthConfig, AuthType
from hopeit.server.logger import engine_extra_logger

__all__ = [
    'init', 'new_token', 'decode_token', 'validate_token',
    'validate_auth_method', 'AuthType'
]

logger, extra = engine_extra_logger()

auth_config: Optional[AuthConfig] = None
private_keys: Dict[str, RSAPrivateKey] = {}
public_keys: Dict[str, RSAPublicKey] = {}
rejected_apps: Set[str] = set()


def init(app_key: str, app_auth_config: AuthConfig):
    """
    loads or creates RSA private/public keys that will be used to create, validate and decode tokens

    :param auth_config: AuthConfig, authorization/authentication server configuration
    """
    global public_keys, private_keys, auth_config
    logger.info(__name__,
def _get_engine_extra_logger(monkeypatch, mock_app_config):  # noqa: F811
    _patch_logger(monkeypatch)
    logger, extra = server_logging.engine_extra_logger()
    logger.init_server(mock_app_config.server)
    logger.init_app(mock_app_config, plugins=[])
    return logger, extra