1- from typing import Any , Dict , Optional , Sequence , List , Union , Protocol
1+ from abc import ABC , abstractmethod
2+ from typing import Any , Dict , List , Optional , Protocol , Sequence , Union
23
34import jwt
45from jwt .exceptions import InvalidIssuerError , InvalidTokenError
@@ -36,10 +37,14 @@ def get_kid(token: str) -> Optional[str]:
3637class JWTValidatorProtocol (Protocol ):
3738 """Protocol defining the interface for JWT validators"""
3839
39- async def validate_jwt (self , access_token : str ) -> Dict [str , Any ]: ...
40+ async def validate_jwt (self , access_token : str ) -> Dict [str , Any ]:
41+ """
42+ Validates an access token and returns its claims.
43+ """
44+ ...
4045
4146
42- class BaseJWTValidator :
47+ class BaseJWTValidator ( ABC ) :
4348 """Base class for JWT validators with common functionality."""
4449
4550 def __init__ (
@@ -54,6 +59,12 @@ def __init__(
5459 self ._algorithms = list (algorithms )
5560 self .logger = get_logger ()
5661
62+ @abstractmethod
63+ async def validate_jwt (self , access_token : str ) -> Dict [str , Any ]:
64+ """
65+ Validates an access token and returns its claims.
66+ """
67+
5768
5869class AsymmetricJWTValidator (BaseJWTValidator ):
5970 """
@@ -235,8 +246,8 @@ def __init__(
235246 for algorithm in algorithms :
236247 if algorithm not in supported_algorithms :
237248 raise ValueError (
238- f"Algorithm '{ algorithm } ' is not supported for symmetric validation. "
239- f"Use one of: { ', ' .join (supported_algorithms )} "
249+ f"Algorithm '{ algorithm } ' is not supported for symmetric "
250+ f"validation. Use one of: { ', ' .join (supported_algorithms )} . "
240251 )
241252
242253 self ._secret_key = secret_key
0 commit comments