diff options
author | Frederick Muriuki Muriithi | 2024-10-09 16:29:16 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-10-09 16:38:23 -0500 |
commit | e856c43aa538c03afddb1b9424a0bac7408639d5 (patch) | |
tree | 9fe4fb245d5c24aa1fb98efa79c77eaa227020a6 /gn_auth/auth/authentication/oauth2/models | |
parent | bdf85093f8b64d4137eb075e5b6e28d16f9dd32f (diff) | |
download | gn-auth-e856c43aa538c03afddb1b9424a0bac7408639d5.tar.gz |
Add a client to the JWTBearerToken objects.
Diffstat (limited to 'gn_auth/auth/authentication/oauth2/models')
-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 index 2606ac6..cca75f4 100644 --- a/gn_auth/auth/authentication/oauth2/models/jwt_bearer_token.py +++ b/gn_auth/auth/authentication/oauth2/models/jwt_bearer_token.py @@ -5,11 +5,26 @@ 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 +from gn_auth.auth.authentication.oauth2.models.oauth2client import ( + client as fetch_client) class JWTBearerToken(_JWTBearerToken): """Overrides default JWTBearerToken class.""" def __init__(self, payload, header, options=None, params=None): + """Initialise the bearer token.""" + # TOD0: Maybe remove this init and make this a dataclass like the way + # OAuth2Client is a dataclass super().__init__(payload, header, options, params) self.user = with_db_connection( lambda conn:user_by_id(conn, uuid.UUID(payload["sub"]))) + self.client = with_db_connection( + lambda conn: fetch_client( + conn, uuid.UUID(payload["oauth2_client_id"]) + ) + ).maybe(None, lambda _client: _client) + + + def check_client(self, client): + """Check that the client is right.""" + return self.client.get_client_id() == client.get_client_id() |