1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-02 07:47:32 +00:00

Update repo_api_tokens.py (#6793)

This commit is contained in:
Ranjiwei 2024-09-20 12:38:02 +08:00 committed by GitHub
parent 026e66b8ec
commit 6746e5ab1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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'