Exemplo n.º 1
0
def requestic1(key):
    key = int("{}".format(key))
    data = json.loads(request.data)
    Jwt1 = request.headers['Authorization']
    message = data.get("message")
    try:
        jwt_Obj = PyJWT()
        decode_token = jwt_Obj.decode(str(Jwt1), key=Key)
        if decode_token['role'] == "write":
            if key == None or message == None:
                return Response(status=400)
            else:
                cache = redis.Redis(host=HOST, port=6379)
                cache.ping()
                if cache.exists(key):
                    cache.delete(key)
                    cache.set(key, json.dumps(message))
                    return make_response("changed", 200)
                else:
                    cache.set(key, json.dumps(message))
                    return make_response({key: message}, 201)
        else:
            return make_response("invalid1 tiket", 400)
    except Exception:
        return make_response("invalid2 tiket", 400)
Exemplo n.º 2
0
def requestic2(key):
    key = int("{}".format(key))
    Jwt1 = request.headers['Authorization']
    try:
        jwt_Obj = PyJWT()
        decode_token = jwt_Obj.decode(str(Jwt1), key=Key)
        if decode_token['role'] == "read":
            cache = redis.Redis(host=HOST, port=6379)
            cache.ping()
            if cache.exists(key):
                res = json.loads(cache.get(key))
                return make_response({"message": res}, 200)
            else:
                return Response(status=400)
        else:
            return make_response("invalid1 tiket", 400)
    except Exception:
        return make_response("invalid2 tiket", 400)
Exemplo n.º 3
0
    def authenticate(self, request):
        print('sadas')

        rawToken = get_authorization_header(request)
        print(request.data)
        print(rawToken)

        key = 'secretmustbecomplex'
        jwt_Obj = PyJWT()

        if not rawToken:
            return None
        payload = jwt_Obj.decode(rawToken, key=key)
        email = payload['email']
        password = payload['password']
        try:
            user = UserProfile.objects.get(email=email, password=password)
        except UserProfile.DoesNotExist:
            raise exceptions.AuthenticationFailed('No such user')

        return (user, None)
Exemplo n.º 4
0
from jwt.api_jwt import PyJWT

payload = {'id': 5, 'email': 'ASDASDA'}

key = 'secret'

jwt_Obj = PyJWT()
jwt_token = jwt_Obj.encode(payload=payload, key=key)
decode_token = jwt_Obj.decode(jwt_token, key=key)

print(jwt_token)
print(decode_token)