SHARE
TWEET

Untitled

a guest Feb 20th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from django.utils.text import gettext_lazy as _
  2. from rest_framework import serializers
  3. from rest_framework_simplejwt.tokens import RefreshToken, TokenError
  4.  
  5. class RefreshTokenSerializer(serializers.Serializer):
  6.     refresh = serializers.CharField()
  7.  
  8.     default_error_messages = {
  9.         'bad_token': _('Token is invalid or expired')
  10.     }
  11.  
  12.     def validate(self, attrs):
  13.         self.token = attrs['refresh']
  14.         return attrs
  15.  
  16.     def save(self, **kwargs):
  17.         try:
  18.             RefreshToken(self.token).blacklist()
  19.         except TokenError:
  20.             self.fail('bad_token')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top