From b8358348e1ab18853906990befe934149b24acec Mon Sep 17 00:00:00 2001 From: Yasser Tahiri Date: Sun, 25 Jun 2023 00:28:19 +0400 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20remove=20deprecated=20=20`?= =?UTF-8?q?parse=5Fobj`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- authx/schema.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/authx/schema.py b/authx/schema.py index 7a2b5b6b..0de95645 100644 --- a/authx/schema.py +++ b/authx/schema.py @@ -108,11 +108,13 @@ def decode( cls, token: str, key: str, - algorithms: Sequence[AlgorithmType] = ["HS256"], + algorithms: Sequence[AlgorithmType] = None, audience: Optional[StringOrSequence] = None, issuer: Optional[str] = None, verify: bool = True, ) -> "TokenPayload": + if algorithms is None: + algorithms = ["HS256"] payload = decode_token( token=token, key=key, @@ -121,7 +123,7 @@ def decode( issuer=issuer, verify=verify, ) - return cls.parse_obj(payload) + return cls.model_validate(payload) class RequestToken(BaseModel): @@ -133,7 +135,7 @@ class RequestToken(BaseModel): def verify( self, key: str, - algorithms: Sequence[AlgorithmType] = ["HS256"], + algorithms: Sequence[AlgorithmType] = None, audience: Optional[StringOrSequence] = None, issuer: Optional[str] = None, verify_jwt: bool = True, @@ -141,6 +143,8 @@ def verify( verify_csrf: bool = True, verify_fresh: bool = False, ) -> TokenPayload: + if algorithms is None: + algorithms = ["HS256"] # JWT Base Verification try: decoded_token = decode_token( @@ -152,7 +156,7 @@ def verify( issuer=issuer, ) # Parse payload - payload = TokenPayload.parse_obj(decoded_token) + payload = TokenPayload.model_validate(decoded_token) except JWTDecodeError as e: raise JWTDecodeError(*e.args) from e except ValidationError as e: