From 6746e5ab1d5aada22ff80d31723c1fd45d2fa281 Mon Sep 17 00:00:00 2001 From: Ranjiwei <32759763+r350178982@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:38:02 +0800 Subject: [PATCH] Update repo_api_tokens.py (#6793) --- seahub/api2/endpoints/repo_api_tokens.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/seahub/api2/endpoints/repo_api_tokens.py b/seahub/api2/endpoints/repo_api_tokens.py index 70a16fcb5d..090714b76d 100644 --- a/seahub/api2/endpoints/repo_api_tokens.py +++ b/seahub/api2/endpoints/repo_api_tokens.py @@ -1,5 +1,5 @@ import logging - +import jwt from rest_framework import status from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAuthenticated @@ -10,7 +10,7 @@ from django.utils.translation import gettext as _ from seahub.api2.authentication import TokenAuthentication from seahub.api2.throttling import UserRateThrottle -from seahub.api2.utils import api_error +from seahub.api2.utils import api_error, JWT_PRIVATE_KEY from seaserv import seafile_api @@ -175,9 +175,14 @@ class RepoNotificationJwtTokenView(APIView): if not seafile_api.check_permission_by_path(repo_id, '/', username): error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) - + try: - jwt_token = seafile_api.gen_notif_server_jwt(repo_id, username) + payload = { + 'username': username, + 'repo_id': repo_id, + 'exp': 3 * 3600 * 24 # default by three days + } + jwt_token = jwt.encode(payload, JWT_PRIVATE_KEY, algorithm='HS256') except Exception as e: logger.error(e) error_msg = 'Internal Server Error'