diff options
author | Frederick Muriuki Muriithi | 2024-07-26 16:55:27 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-07-31 09:30:27 -0500 |
commit | acb696a15887e9088c0caf40ff020f28438acb59 (patch) | |
tree | bf90c8ee0cab5b437dd72f7469dfbf681df86e22 | |
parent | 00e21e4a02cd6718a466f4f26f62fc790c1ada3a (diff) | |
download | gn-auth-acb696a15887e9088c0caf40ff020f28438acb59.tar.gz |
Extend default JWTBearerToken to include a user member.
-rw-r--r-- | gn_auth/auth/authentication/oauth2/models/jwt_bearer_token.py | 15 |
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"]))) |