diff options
| author | 2020-12-01 09:54:22 +0200 | |
|---|---|---|
| committer | 2020-12-01 09:54:22 +0200 | |
| commit | 6a6d28038494626ed74fc842c814477b16af1e75 (patch) | |
| tree | f36141cb67eb1e93d9813f3e2934b8acccc92855 /backend/authentication/user.py | |
| parent | Update SCHEMA.md (diff) | |
Create BaseUser implementation for JWT authentication
Diffstat (limited to '')
| -rw-r--r-- | backend/authentication/user.py | 22 | 
1 files changed, 22 insertions, 0 deletions
| diff --git a/backend/authentication/user.py b/backend/authentication/user.py new file mode 100644 index 0000000..afa243f --- /dev/null +++ b/backend/authentication/user.py @@ -0,0 +1,22 @@ +import typing as t +from abc import ABC + +from starlette.authentication import BaseUser + + +class User(BaseUser, ABC): +    """Starlette BaseUser implementation for JWT authentication.""" + +    def __init__(self, token: str, payload: t.Dict) -> None: +        self.token = token +        self.payload = payload + +    @property +    def is_authenticated(self) -> bool: +        """Returns True because user is always authenticated at this stage.""" +        return True + +    @property +    def display_name(self) -> str: +        """Return username and discriminator as display name.""" +        return f"{self.payload['username']}#{self.payload['discriminator']}" | 
