Esempio n. 1
0
def auth_token(
    config: Config,
    logger: Logger,
) -> Generator[Dict[str, str], None, None]:
    retailer_repository = RetailerRepository(config, logger)
    auth_service = AuthService(config, logger, retailer_repository)

    reatailer_model = RetailerModel(
        full_name="Authenticated User",
        document="99899899899",
        email=EmailStr("*****@*****.**"),
        password="******",
    )

    retailer_repository.insert_retailer(reatailer_model)
    retailer = retailer_repository.get_retailer_by_email("*****@*****.**")

    auth_token = auth_service.generate_access_token(
        {"sub": "*****@*****.**"},
        expires_delta=timedelta(
            minutes=int(config.get_config("ACCESS_TOKEN_EXPIRE_MINUTES"))
        ),
    )

    yield {"Authorization": f"Bearer {auth_token}"}
    if retailer:
        retailer_repository.delete_retailer(retailer.id)
Esempio n. 2
0
 def token(
     self, expires_delta: timedelta, data: Dict[str, Any], auth_service: AuthService
 ) -> str:
     return auth_service.generate_access_token(data, expires_delta)