<s> import json <EOL> from braces . views import CsrfExemptMixin <EOL> from oauth2_provider . ext . rest_framework import OAuth2Authentication <EOL> from oauth2_provider . models import Application , AccessToken <EOL> from oauth2_provider . settings import oauth2_settings <EOL> from oauth2_provider . views . mixins import OAuthLibMixin <EOL> from rest_framework import permissions <EOL> from rest_framework import status <EOL> from rest_framework . decorators import api_view , authentication_classes , permission_classes <EOL> from rest_framework . response import Response <EOL> from rest_framework . views import APIView <EOL> from . oauth2_backends import KeepRequestCore <EOL> from . oauth2_endpoints import SocialTokenServer <EOL> class ConvertTokenView ( CsrfExemptMixin , OAuthLibMixin , APIView ) : <EOL> """<STR_LIT>""" <EOL> server_class = SocialTokenServer <EOL> validator_class = oauth2_settings . OAUTH2_VALIDATOR_CLASS <EOL> oauthlib_backend_class = KeepRequestCore <EOL> permission_classes = ( permissions . AllowAny , ) <EOL> def post ( self , request , * args , ** kwargs ) : <EOL> request . _request . POST = request . _request . POST . copy ( ) <EOL> for key , value in request . data . items ( ) : <EOL> request . _request . POST [ key ] = value <EOL> url , headers , body , status = self . create_token_response ( request . _request ) <EOL> response = Response ( data = json . loads ( body ) , status = status ) <EOL> for k , v in headers . items ( ) : <EOL> response [ k ] = v <EOL> return response <EOL> @ api_view ( [ '<STR_LIT:POST>' ] ) <EOL> @ authentication_classes ( [ OAuth2Authentication ] ) <EOL> @ permission_classes ( [ permissions . IsAuthenticated ] ) <EOL> def invalidate_sessions ( request ) : <EOL> client_id = request . POST . get ( "<STR_LIT>" , None ) <EOL> if client_id is None : <EOL> return Response ( { <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] <EOL> } , status = status . HTTP_400_BAD_REQUEST ) <EOL> try : <EOL> app = Application . objects . get ( client_id = client_id ) <EOL> except Application . DoesNotExist : <EOL> return Response ( { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , status = status . HTTP_400_BAD_REQUEST ) <EOL> tokens = AccessToken . objects . filter ( user = request . user , application = app ) <EOL> tokens . delete ( ) <EOL> return Response ( { } , status = status . HTTP_204_NO_CONTENT ) </s>
