JWT认证 - 大江狗的博客
https://pythondjango.cn/django/rest-framework/7-jwt-token-authentication该序列化器继承了TokenObtainPairSerializer类。 from rest_framework_simplejwt.serializers import TokenObtainPairSerializer class MyTokenObtainPairSerializer ( TokenObtainPairSerializer ): @ classmethod def get_token ( cls , user ): token = super ( MyTokenObtainPairSerializer , cls ). get_token ( user ) # 添加额外信息 token [ 'username' ] = user . username return token
python - Stack Overflow
https://stackoverflow.com/questions/5697842409.07.2019 · You can do this by creating a custom serializer that inherits from TokenObtainPairSerializer, and extending the validate method to check for custom field values. There is no architecture problem if you are careful to not override necessary functionality of the parent class. Here is an example:
关于json:从django-rest-framework-simplejwt定制JWT响应 | 码农 …
https://www.codenong.com/5454497816.07.2020 · from rest_framework_simplejwt.serializers import TokenObtainPairSerializer class MyTokenObtainPairSerializer(TokenObtainPairSerializer): @classmethod def get_token(cls, user): token = super().get_token(user) # Add custom claims token['name'] = user.name # Add more custom fields from your custom user model, If you have a # custom user model. # ...