aboutsummaryrefslogtreecommitdiffstats
path: root/backend/authentication/user.py
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2020-12-01 20:25:14 +0000
committerGravatar GitHub <[email protected]>2020-12-01 20:25:14 +0000
commit700b504af2e6e1ff0de5246b058928c0cc934be5 (patch)
tree250826482ce439492adcccbdae2f09e56fa1a44e /backend/authentication/user.py
parentUpdate SCHEMA.md (diff)
parentAdd user property to index response (diff)
Merge pull request #12 from python-discord/ks123/admin-authentication
Diffstat (limited to 'backend/authentication/user.py')
-rw-r--r--backend/authentication/user.py22
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']}"