-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthentication.py
More file actions
23 lines (19 loc) · 792 Bytes
/
authentication.py
File metadata and controls
23 lines (19 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import rest_framework_simplejwt.authentication
import rest_framework_simplejwt.exceptions
class CustomJWTAuthentication(
rest_framework_simplejwt.authentication.JWTAuthentication,
):
def authenticate(self, request):
try:
user_token = super().authenticate(request)
except rest_framework_simplejwt.exceptions.InvalidToken:
raise rest_framework_simplejwt.exceptions.AuthenticationFailed(
'Token is invalid or expired',
)
if user_token:
user, token = user_token
if token.payload.get('token_version') != user.token_version:
raise rest_framework_simplejwt.exceptions.AuthenticationFailed(
'Token invalid',
)
return user_token