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-25 14:21:12 +02:00
|
|
|
from .authenticator import Authenticator, AuthError, 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:
|
2021-05-25 14:21:12 +02:00
|
|
|
raise AuthError("TFA authenticator does not support usernames")
|
2021-05-15 18:27:16 +02:00
|
|
|
|
|
|
|
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]:
|
2021-05-25 14:21:12 +02:00
|
|
|
raise AuthError("TFA authenticator does not support usernames")
|
2021-05-15 18:27:16 +02:00
|
|
|
|
|
|
|
def invalidate_username(self) -> None:
|
2021-05-25 14:21:12 +02:00
|
|
|
raise AuthError("TFA authenticator does not support usernames")
|
2021-05-15 18:27:16 +02:00
|
|
|
|
|
|
|
def invalidate_password(self) -> None:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def invalidate_credentials(self) -> None:
|
|
|
|
pass
|