TS-ResHub/utils/auth.py
2025-04-15 15:16:58 +08:00

17 lines
450 B
Python

from ninja.security import HttpBearer
from rest_framework_simplejwt.authentication import JWTAuthentication
class JWTAuth(HttpBearer):
def authenticate(self, request, token):
jwt_auth = JWTAuthentication()
try:
validated_token = jwt_auth.get_validated_token(token)
user = jwt_auth.get_user(validated_token)
return user
except Exception:
return None
jwt_auth = JWTAuth()