Exemplo n.º 1
0
    def validate(self, attrs):
        """
        2019/08/30

        :param attrs:
        :return:
        """
        requested_cookies = self.context['request'].COOKIES

        try:
            token = SlidingToken(requested_cookies['JWT'])
        except Exception:
            raise exceptions.APIException("Invalid token")

        # Check that the timestamp in the "refresh_exp" claim has not
        # passed
        token.check_exp(api_settings.SLIDING_TOKEN_REFRESH_EXP_CLAIM)

        # Update the "exp" claim
        token.set_exp()

        refreshed_token = jwt.decode(
            str(token).encode('utf-8'), settings.SECRET_KEY)

        requested_refresh_token = jwt.decode(
            requested_cookies['SESSION'].encode('utf-8'), settings.SECRET_KEY)

        return {
            'token':
            str(token),
            'session_token':
            str(
                _session_token_generator(user_info=requested_refresh_token,
                                         exp=refreshed_token['exp']))
        }
Exemplo n.º 2
0
    def validate(self, attrs):
        token = SlidingToken(attrs['token'], verify=False)

        # Check that the timestamp in the "refresh_exp" claim has not
        # passed
        token.check_exp(api_settings.SLIDING_TOKEN_REFRESH_EXP_CLAIM)

        # Update the "exp" claim
        token.set_exp()

        return {'token': text_type(token)}