diff options
author | Frederick Muriuki Muriithi | 2024-05-02 07:47:32 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-05-02 07:47:32 +0300 |
commit | 77a58474da1b3827b3683b0195bc7cbacddbaf4a (patch) | |
tree | b7a8745e623be9b778c857c8ca265fa1b3e4681d /gn_auth/auth/authentication/oauth2/models | |
parent | bd8324ebdf0b94c64f6e6ff2fa732e7cd1f0b6ef (diff) | |
download | gn-auth-77a58474da1b3827b3683b0195bc7cbacddbaf4a.tar.gz |
Compute and cache the client's KeySet.
Diffstat (limited to 'gn_auth/auth/authentication/oauth2/models')
-rw-r--r-- | gn_auth/auth/authentication/oauth2/models/oauth2client.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/gn_auth/auth/authentication/oauth2/models/oauth2client.py b/gn_auth/auth/authentication/oauth2/models/oauth2client.py index 0f40688..f48cbce 100644 --- a/gn_auth/auth/authentication/oauth2/models/oauth2client.py +++ b/gn_auth/auth/authentication/oauth2/models/oauth2client.py @@ -1,12 +1,14 @@ """OAuth2 Client model.""" import json import datetime +from pathlib import Path from uuid import UUID from dataclasses import dataclass from functools import cached_property from typing import Sequence, Optional +from authlib.jose import KeySet, JsonWebKey from authlib.oauth2.rfc6749 import ClientMixin from pymonad.maybe import Just, Maybe, Nothing @@ -55,6 +57,17 @@ class OAuth2Client(ClientMixin): """ return self.client_metadata.get("client_type", "public") + @cached_property + def jwks(self) -> KeySet: + """Return this client's KeySet.""" + def __parse_key__(keypath: Path) -> JsonWebKey:# pylint: disable=[unspecified-encoding] + with open(keypath) as _key: + return JsonWebKey.import_key(_key.read()) + + return KeySet([ + __parse_key__(Path(pth)) + for pth in self.client_metadata.get("public_keys", [])]) + def check_endpoint_auth_method(self, method: str, endpoint: str) -> bool: """ Check if the client supports the given method for the given endpoint. |