<s> import logging <EOL> import warnings <EOL> from rest_framework import serializers <EOL> from rest_framework . authtoken . models import Token <EOL> from django . contrib . auth import get_user_model <EOL> l = logging . getLogger ( __name__ ) <EOL> class OAuth2InputSerializer ( serializers . Serializer ) : <EOL> provider = serializers . CharField ( required = False ) <EOL> code = serializers . CharField ( ) <EOL> redirect_uri = serializers . CharField ( required = False ) <EOL> class OAuth1InputSerializer ( serializers . Serializer ) : <EOL> provider = serializers . CharField ( required = False ) <EOL> oauth_token = serializers . CharField ( ) <EOL> oauth_verifier = serializers . CharField ( ) <EOL> class UserSerializer ( serializers . ModelSerializer ) : <EOL> class Meta : <EOL> model = get_user_model ( ) <EOL> exclude = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:password>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> class TokenSerializer ( serializers . Serializer ) : <EOL> token = serializers . SerializerMethodField ( ) <EOL> def get_token ( self , obj ) : <EOL> token , created = Token . objects . get_or_create ( user = obj ) <EOL> return token . key <EOL> class UserTokenSerializer ( TokenSerializer , UserSerializer ) : <EOL> pass <EOL> class JWTSerializer ( TokenSerializer ) : <EOL> def get_token ( self , obj ) : <EOL> try : <EOL> from rest_framework_jwt . settings import api_settings <EOL> except ImportError : <EOL> warnings . warn ( '<STR_LIT>' , <EOL> ImportWarning ) <EOL> raise <EOL> jwt_payload_handler = api_settings . JWT_PAYLOAD_HANDLER <EOL> jwt_encode_handler = api_settings . JWT_ENCODE_HANDLER <EOL> payload = jwt_payload_handler ( self . get_jwt_payload ( obj ) ) <EOL> token = jwt_encode_handler ( payload ) <EOL> return token <EOL> def get_jwt_payload ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> return obj <EOL> class UserJWTSerializer ( JWTSerializer , UserSerializer ) : <EOL> pass </s>
