-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DOP-23149] Replace python-jose with pyjwt
- Loading branch information
Showing
5 changed files
with
47 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,25 @@ | ||
# SPDX-FileCopyrightText: 2024 MTS PJSC | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from jose import ExpiredSignatureError, JWTError, jwt | ||
import jwt | ||
|
||
from data_rentgen.exceptions.auth import AuthorizationError | ||
|
||
|
||
def sign_jwt(payload: dict, secret_key: str, security_algorithm: str) -> str: | ||
return jwt.encode( | ||
payload, | ||
secret_key, | ||
payload=payload, | ||
key=secret_key, | ||
algorithm=security_algorithm, | ||
) | ||
|
||
|
||
def decode_jwt(token: str, secret_key: str, security_algorithm: str) -> dict: | ||
try: | ||
result = jwt.decode( | ||
token, | ||
secret_key, | ||
algorithms=[security_algorithm], | ||
) | ||
if "exp" not in result: | ||
raise ExpiredSignatureError("Missing expiration time in token") | ||
claims = jwt.decode(jwt=token, key=secret_key, algorithms=[security_algorithm]) | ||
|
||
return result | ||
except JWTError as e: | ||
if "exp" not in claims: | ||
raise jwt.exceptions.ExpiredSignatureError("Missing expiration time in token") | ||
|
||
return claims | ||
except jwt.exceptions.InvalidTokenError as e: | ||
raise AuthorizationError("Invalid token") from e |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters