Ejemplo n.º 1
0
 def post(self):
     jti = get_raw_jwt()["jti"]
     try:
         TokenModel.revoke_token(jti=jti)
         return jsonify({"msg": "Refresh token revoked."}), 200
     except TokenNotFound:
         return jsonify({"msg": "The specified token was not found"}), 404
Ejemplo n.º 2
0
    def put(self, token_id):
        json_data = request.get_json(silent=True)
        if not json_data:
            return jsonify({"msg": "Missing 'revoke' in body"}), 400
        revoke = json_data.get("revoke", None)
        if revoke is None:
            return jsonify({"msg": "Missing 'revoke' in body"}), 400
        if not isinstance(revoke, bool):
            return jsonify({"msg": "'revoke' must be a boolean"}), 400

        current_user = get_jwt_identity()
        try:
            if revoke:
                TokenModel.revoke_token(token_id, current_user)
                return jsonify({"msg": "Token revoked"}), 200
            else:
                TokenModel.unrevoke_token(token_id, current_user)
                return jsonify({"msg": "Token unrevoked"}), 200
        except TokenNotFound:
            return jsonify({"msg": "The specified token was not found"}), 404