|
| 1 | +from datetime import UTC, datetime |
| 2 | + |
1 | 3 | import jwt |
| 4 | +from django.conf import settings |
2 | 5 | from django.utils.translation import gettext_lazy as _ |
3 | 6 | from drf_spectacular.contrib.rest_framework_jwt import JWTScheme |
4 | 7 | from rest_framework.exceptions import AuthenticationFailed |
5 | 8 | from rest_framework.request import Request |
6 | 9 | from rest_framework_jwt.authentication import JSONWebTokenAuthentication |
7 | | -from rest_framework_jwt.utils import jwt_create_payload |
8 | 10 |
|
9 | 11 | from apps.a12n.models import JWTBlacklist |
10 | 12 | from apps.users.models import User |
11 | 13 |
|
12 | 14 |
|
13 | | -def payload_handler(user: User) -> dict: |
14 | | - """Add app-wide payload to generated JWT's""" |
| 15 | +def create_jwt_payload(user: User) -> dict: |
| 16 | + """App-wide JWT payload. |
| 17 | +
|
| 18 | + original function is at https://github.com/Styria-Digital/django-rest-framework-jwt/blob/master/src/rest_framework_jwt/utils.py#L59 |
| 19 | + """ |
| 20 | + |
| 21 | + issued_at = datetime.now(tz=UTC) |
| 22 | + |
15 | 23 | return { |
16 | | - **jwt_create_payload(user), |
| 24 | + "username": user.get_username(), |
| 25 | + "iat": issued_at.timestamp(), |
| 26 | + "exp": issued_at + settings.JWT_AUTH["JWT_EXPIRATION_DELTA"], |
| 27 | + "orig_iat": issued_at.timestamp(), |
| 28 | + "iss": settings.JWT_AUTH["JWT_ISSUER"], |
| 29 | + "user_id": user.pk, |
17 | 30 | "user_public_id": user.uuid, |
18 | 31 | } |
19 | 32 |
|
|
0 commit comments