aboutsummaryrefslogtreecommitdiff
path: root/gn_auth
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-07-26 16:55:27 -0500
committerFrederick Muriuki Muriithi2024-07-31 09:30:27 -0500
commitacb696a15887e9088c0caf40ff020f28438acb59 (patch)
treebf90c8ee0cab5b437dd72f7469dfbf681df86e22 /gn_auth
parent00e21e4a02cd6718a466f4f26f62fc790c1ada3a (diff)
downloadgn-auth-acb696a15887e9088c0caf40ff020f28438acb59.tar.gz
Extend default JWTBearerToken to include a user member.
Diffstat (limited to 'gn_auth')
-rw-r--r--gn_auth/auth/authentication/oauth2/models/jwt_bearer_token.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/gn_auth/auth/authentication/oauth2/models/jwt_bearer_token.py b/gn_auth/auth/authentication/oauth2/models/jwt_bearer_token.py
new file mode 100644
index 0000000..2606ac6
--- /dev/null
+++ b/gn_auth/auth/authentication/oauth2/models/jwt_bearer_token.py
@@ -0,0 +1,15 @@
+"""Implement model for JWTBearerToken"""
+import uuid
+
+from authlib.oauth2.rfc7523 import JWTBearerToken as _JWTBearerToken
+
+from gn_auth.auth.db.sqlite3 import with_db_connection
+from gn_auth.auth.authentication.users import user_by_id
+
+class JWTBearerToken(_JWTBearerToken):
+ """Overrides default JWTBearerToken class."""
+
+ def __init__(self, payload, header, options=None, params=None):
+ super().__init__(payload, header, options, params)
+ self.user = with_db_connection(
+ lambda conn:user_by_id(conn, uuid.UUID(payload["sub"])))