示例#1
0
 def create(self, request):
     """
         post method
     """
     # Here we will try to refresh the token.
     try:
         refresh_token = RefreshToken(request.data.get("refresh"))
         refresh_token.verify()
         # If the token can be verified then refresh
         # the access token.
         response = {
             "access": str(refresh_token.access_token),
             "refresh": str(refresh_token),
         }
         response_status = status.HTTP_200_OK
         return Response(response, status=response_status)
     # If the token cannot be verified it will throw
     # a "TokenError".
     except TokenError:
         # If the TokenError has been thrown then
         # return an error in the response.
         response = {"detail": _("Could not refresh token.")}
         response_status = status.HTTP_401_UNAUTHORIZED
         return Response(response, status=response_status)
示例#2
0
 def post(self, request):
     user = request.user
     RefreshToken.verify()
     token = RefreshToken.for_user(user)
     token = {"refresh": str(token), "access": str(token.access_token)}
     return Response(token)