Level up your Box knowledge with brand new learning paths on Box University. Visit training.box.com to get started

python boxsdk3 webhook.validate_message returns false

New post

Comments

2 comments

  • Alex Novotny

    Hi, 

    Can I see some of the code you are running? Also - the client id of your application would be helpful!

    0
    Comment actions Permalink
  • mediLab AI

    Sorry for the late response.

    The code and id is below!!
    is_valid in download_image_from_box() becomes False.
    box_secret.json used in get_box_client() is configuration json.

    image, box_file_id = download_image_from_box({"body": request.body, "headers": request.headers})

    def download_image_from_box(event: dict) -> None:

        client, webhook_key, folderName = get_box_client()
        raw_body = event["body"]
        body = json.loads(raw_body)
        webhook_id = body["webhook"]["id"]

        webhook = client.webhook(webhook_id)
        is_valid = webhook.validate_message(raw_body, event["headers"], webhook_key)

    def get_box_client():

        json_open = open('box_secret.json', 'r')
        secret = json.load(json_open)
        client_id = secret["boxAppSettings"]["clientID"]
        client_secret = secret["boxAppSettings"]["clientSecret"]
        jwt_key_id = secret["boxAppSettings"]["appAuth"]["publicKeyID"]
        rsa_private_key_data = secret["boxAppSettings"]["appAuth"]["privateKey"]
        rsa_private_key_passphrase = secret["boxAppSettings"]["appAuth"]["passphrase"]
        enterprise_id = secret["enterpriseID"]
        folderName = secret["folderName"]

        webhook_signature_key = secret["webhookPrimaryKey"]
        auth = JWTAuth(
            client_id=client_id,
            client_secret=client_secret,
            jwt_key_id=jwt_key_id,
            rsa_private_key_data=rsa_private_key_data,
            rsa_private_key_passphrase=rsa_private_key_passphrase,
            enterprise_id=enterprise_id
        )
        auth.authenticate_instance()

        client = Client(auth)
        return client, webhook_signature_key, folderName
    $ box webhooks
    ----- Webhook 574783230 -----
    ID: '574783230'
    Type: webhook
    Target:
        ID: '128629204110'
        Type: folder
    0
    Comment actions Permalink

Post is closed for comments.