pferd/PFERD/auth/tfa.py

31 lines
865 B
Python
Raw Normal View History

2021-05-15 18:27:16 +02:00
from typing import Tuple
from ..logging import log
2021-05-15 18:27:16 +02:00
from ..utils import ainput
from .authenticator import Authenticator, AuthError
2021-05-15 18:27:16 +02:00
class TfaAuthenticator(Authenticator):
2021-05-31 18:21:18 +02:00
def __init__(self, name: str) -> None:
super().__init__(name)
2021-05-15 18:27:16 +02:00
async def username(self) -> str:
raise AuthError("TFA authenticator does not support usernames")
2021-05-15 18:27:16 +02:00
async def password(self) -> str:
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 AuthError("TFA authenticator does not support usernames")
2021-05-15 18:27:16 +02:00
def invalidate_username(self) -> None:
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