2222from botocore .config import Config
2323from botocore .errorfactory import ClientError
2424from cryptography .fernet import Fernet
25- from joserfc .jws import KeySet
25+ from joserfc .jwk import JWKRegistry , KeySet
2626from pydantic import (
27+ AliasChoices ,
2728 AnyUrl ,
2829 BeforeValidator ,
2930 Field ,
@@ -70,7 +71,7 @@ def __init__(self, data: str):
7071
7172
7273def _maybe_load_keys_from_file (value : Any ) -> Any :
73- """Load private keys from files if needed."""
74+ """Load jwks from files if needed."""
7475 if isinstance (value , str ):
7576 # If the value is a string, we need to check if it is a JSON string or a file URL
7677 if not (value .strip ().startswith ("{" ) or value .startswith ("[" )):
@@ -85,8 +86,16 @@ def _maybe_load_keys_from_file(value: Any) -> Any:
8586 return value
8687
8788
89+ def _maybe_load_and_wrap_single_key (value : Any ) -> Any :
90+ if isinstance (value , str ) and value .strip ().startswith ("-----BEGIN" ):
91+ return json .dumps (KeySet (keys = [JWKRegistry .import_key (value )]).as_dict (private = True )) # type: ignore
92+ return value
93+
94+
8895TokenSigningKeyStore = Annotated [
89- _TokenSigningKeyStore , BeforeValidator (_maybe_load_keys_from_file )
96+ _TokenSigningKeyStore ,
97+ BeforeValidator (_maybe_load_keys_from_file ),
98+ BeforeValidator (_maybe_load_and_wrap_single_key ),
9099]
91100
92101
@@ -151,7 +160,9 @@ class AuthSettings(ServiceSettingsBase):
151160 state_key : FernetKey
152161
153162 token_issuer : str
154- token_keystore : TokenSigningKeyStore
163+ token_keystore : TokenSigningKeyStore = Field (
164+ validation_alias = AliasChoices ("token_keystore" , "token_key" )
165+ )
155166 token_allowed_algorithms : list [str ] = ["RS256" , "EdDSA" ] # noqa: S105
156167 access_token_expire_minutes : int = 20
157168 refresh_token_expire_minutes : int = 60
0 commit comments