mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Properly invalidate exceptions
The simple authenticator now properly invalidates its credentials. Also, the invalidation functions have been given better names and documentation.
This commit is contained in:
parent
b70b62cef5
commit
d63494908d
@ -42,11 +42,35 @@ class Authenticator(ABC):
|
||||
async def credentials(self) -> Tuple[str, str]:
|
||||
pass
|
||||
|
||||
def invalid_credentials(self) -> None:
|
||||
def invalidate_credentials(self) -> None:
|
||||
"""
|
||||
Tell the authenticator that some or all of its credentials are invalid.
|
||||
|
||||
Authenticators should overwrite this function if they have a way to
|
||||
deal with this issue that is likely to result in valid credentials
|
||||
(e. g. prompting the user).
|
||||
"""
|
||||
|
||||
raise AuthException("Invalid credentials")
|
||||
|
||||
def invalid_username(self) -> None:
|
||||
def invalidate_username(self) -> None:
|
||||
"""
|
||||
Tell the authenticator that specifically its username is invalid.
|
||||
|
||||
Authenticators should overwrite this function if they have a way to
|
||||
deal with this issue that is likely to result in valid credentials
|
||||
(e. g. prompting the user).
|
||||
"""
|
||||
|
||||
raise AuthException("Invalid username")
|
||||
|
||||
def invalid_password(self) -> None:
|
||||
def invalidate_password(self) -> None:
|
||||
"""
|
||||
Tell the authenticator that specifically its password is invalid.
|
||||
|
||||
Authenticators should overwrite this function if they have a way to
|
||||
deal with this issue that is likely to result in valid credentials
|
||||
(e. g. prompting the user).
|
||||
"""
|
||||
|
||||
raise AuthException("Invalid password")
|
||||
|
@ -1,6 +1,6 @@
|
||||
from typing import Optional, Tuple
|
||||
|
||||
from ..authenticator import Authenticator, AuthSection
|
||||
from ..authenticator import Authenticator, AuthException, AuthSection
|
||||
from ..conductor import TerminalConductor
|
||||
from ..config import Config
|
||||
from ..utils import agetpass, ainput
|
||||
@ -42,7 +42,26 @@ class SimpleAuthenticator(Authenticator):
|
||||
|
||||
if self.password is None:
|
||||
self.password = await agetpass("Password: ")
|
||||
else:
|
||||
print("Password: *******")
|
||||
|
||||
return self.username, self.password
|
||||
|
||||
def invalidate_credentials(self) -> None:
|
||||
if self.username_fixed and self.password_fixed:
|
||||
raise AuthException("Configured credentials are invalid")
|
||||
|
||||
if not self.username_fixed:
|
||||
self.username = None
|
||||
if not self.password_fixed:
|
||||
self.password = None
|
||||
|
||||
def invalidate_username(self) -> None:
|
||||
if self.username_fixed:
|
||||
raise AuthException("Configured username is invalid")
|
||||
else:
|
||||
self.username = None
|
||||
|
||||
def invalidate_password(self) -> None:
|
||||
if self.password_fixed:
|
||||
raise AuthException("Configured password is invalid")
|
||||
else:
|
||||
self.password = None
|
||||
|
@ -156,7 +156,7 @@ class KitShibbolethLogin:
|
||||
soup = await self._authenticate_tfa(sess, soup)
|
||||
|
||||
if not self._login_successful(soup):
|
||||
self._auth.invalid_credentials()
|
||||
self._auth.invalidate_credentials()
|
||||
|
||||
# Equivalent: Being redirected via JS automatically
|
||||
# (or clicking "Continue" if you have JS disabled)
|
||||
|
Loading…
Reference in New Issue
Block a user