2021-05-15 18:27:16 +02:00
|
|
|
from typing import Tuple
|
|
|
|
|
|
|
|
from ..config import Config
|
2021-05-18 22:43:46 +02:00
|
|
|
from ..logging import log
|
2021-05-15 18:27:16 +02:00
|
|
|
from ..utils import ainput
|
2021-05-23 19:16:42 +02:00
|
|
|
from .authenticator import Authenticator, AuthException, AuthSection
|
2021-05-15 18:27:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TfaAuthenticator(Authenticator):
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
name: str,
|
|
|
|
section: AuthSection,
|
|
|
|
config: Config,
|
|
|
|
) -> None:
|
2021-05-18 22:43:46 +02:00
|
|
|
super().__init__(name, section, config)
|
2021-05-15 18:27:16 +02:00
|
|
|
|
|
|
|
async def username(self) -> str:
|
|
|
|
raise AuthException("TFA authenticator does not support usernames")
|
|
|
|
|
|
|
|
async def password(self) -> str:
|
2021-05-18 22:43:46 +02:00
|
|
|
async with log.exclusive_output():
|
2021-05-15 18:27:16 +02:00
|
|
|
code = await ainput("TFA code: ")
|
|
|
|
return code
|
|
|
|
|
|
|
|
async def credentials(self) -> Tuple[str, str]:
|
|
|
|
raise AuthException("TFA authenticator does not support usernames")
|
|
|
|
|
|
|
|
def invalidate_username(self) -> None:
|
|
|
|
raise AuthException("TFA authenticator does not support usernames")
|
|
|
|
|
|
|
|
def invalidate_password(self) -> None:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def invalidate_credentials(self) -> None:
|
|
|
|
pass
|