def requestic4():
    user = request.authorization.username
    password = request.authorization.password
    if d.get(user) != None and d[str(user)] == password:
        payload = {"role": str(user)}
        jwt_Obj = PyJWT()
        jwt_token = jwt_Obj.encode(payload=payload, key=Key)
        rez = make_response(str(jwt_token, 'UTF-8'), 200)
        rez.headers['Authorization'] = str(jwt_token, 'UTF-8')
        return rez
    else:
        return make_response(
            "invalid user or password" + str(user) + ' ' + str(password), 400)
Beispiel #2
0
    def post(self, request, *args, **kwargs):
        if not request.data:
            return Response({'Error': "Please provide username/password"},
                            status="400")

        email = request.data['email']
        password = request.data['password']
        print(email, password)

        user = models.UserProfile.objects.get(email=email)

        payload = {'email': user.email, 'password': user.password}
        key = 'secretmustbecomplex'
        jwt_Obj = PyJWT()

        jwt_token = {'token': jwt_Obj.encode(payload=payload, key=key)}

        return Response(jwt_token)
Beispiel #3
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)