Ejemplo n.º 1
0
 async def decorated_function(request, *args, **kwargs):
     try:
         id_dict = deserialize_api_key(
             request.app.config.SECRET_KEY, utils.extract_request_token(request)
         )
         await get_auth_by_next_id(id_dict.get("id"))
     except (ApiNotFound, BadSignature):
         raise ApiUnauthorized("Unauthorized: Invalid bearer token")
     response = await func(request, *args, **kwargs)
     return response
Ejemplo n.º 2
0
async def get_transactor_key(request):
    id_dict = deserialize_api_key(request.app.config.SECRET_KEY, request.token)
    user_id = id_dict.get("id")

    auth_data = await auth_query.fetch_info_by_user_id(
        request.app.config.DB_CONN, user_id)
    encrypted_private_key = auth_data.get("encrypted_private_key")
    private_key = decrypt_private_key(request.app.config.AES_KEY, user_id,
                                      encrypted_private_key)
    hex_private_key = binascii.hexlify(private_key)
    return Key(hex_private_key)
Ejemplo n.º 3
0
async def get_transactor_key(request):
    """Get transactor key out of request."""
    id_dict = deserialize_api_key(request.app.config.SECRET_KEY,
                                  extract_request_token(request))
    next_id = id_dict.get("id")

    auth_data = await get_auth_by_next_id(next_id)
    encrypted_private_key = auth_data.get("encrypted_private_key")
    private_key = decrypt_private_key(request.app.config.AES_KEY, next_id,
                                      encrypted_private_key)
    hex_private_key = binascii.hexlify(private_key)
    return Key(hex_private_key), next_id
Ejemplo n.º 4
0
 async def decorated_function(request, *args, **kwargs):
     if request.token is None:
         raise ApiUnauthorized("Unauthorized: No bearer token provided")
     try:
         id_dict = deserialize_api_key(
             request.app.config.SECRET_KEY, request.token
         )
         await auth_query.fetch_info_by_user_id(
             request.app.config.DB_CONN, id_dict.get("id")
         )
     except (ApiNotFound, BadSignature):
         raise ApiUnauthorized("Unauthorized: Invalid bearer token")
     response = await func(request, *args, **kwargs)
     return response
Ejemplo n.º 5
0
        async def decorated_function(request, *args, **kwargs):
            try:
                id_dict = deserialize_api_key(
                    request.app.config.SECRET_KEY, utils.extract_request_token(request)
                )

                conn = await db_utils.create_connection(
                    request.app.config.DB_HOST,
                    request.app.config.DB_PORT,
                    request.app.config.DB_NAME,
                )

                await auth_query.fetch_info_by_user_id(conn, id_dict.get("id"))

                conn.close()

            except (ApiNotFound, BadSignature):
                raise ApiUnauthorized("Unauthorized: Invalid bearer token")
            response = await func(request, *args, **kwargs)
            return response