Last active
February 9, 2020 08:37
-
-
Save shafi2263/6bb24d5f17acda858ecc61dcec5a6819 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth import get_user_model | |
from rest_framework_simplejwt.serializers import TokenObtainSerializer | |
from rest_framework_simplejwt.tokens import RefreshToken | |
class MyTokenObtainSerializer(TokenObtainSerializer): | |
@classmethod | |
def get_token(cls, user): | |
return RefreshToken.for_user(user) | |
def validate(self, attrs): | |
data = super().validate(attrs) | |
refresh = self.get_token(self.user) | |
data['access'] = str(refresh.access_token) | |
return data | |
def main(): | |
User = get_user_model() | |
user = User.objects.last() | |
user.set_password('Asdf1321!') | |
user.save() | |
data = { | |
'username': user.username, | |
'password': 'Asdf1321!' | |
} | |
serializer = MyTokenObtainSerializer(data=data) | |
serializer.is_valid(raise_exception=True) | |
print(serializer.validated_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment