Skip to content

Commit

Permalink
♻️ remove deprecated parse_obj
Browse files Browse the repository at this point in the history
  • Loading branch information
yezz123 committed Oct 14, 2023
1 parent bad2db3 commit 0502b14
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions authx/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -121,7 +123,7 @@ def decode(
issuer=issuer,
verify=verify,
)
return cls.parse_obj(payload)
return cls.model_validate(payload)


class RequestToken(BaseModel):
Expand All @@ -133,14 +135,16 @@ 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,
verify_type: bool = True,
verify_csrf: bool = True,
verify_fresh: bool = False,
) -> TokenPayload:
if algorithms is None:
algorithms = ["HS256"]
# JWT Base Verification
try:
decoded_token = decode_token(
Expand All @@ -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:
Expand Down

0 comments on commit 0502b14

Please sign in to comment.