0

Simple WebHooks Receiver I'm following this tutorial on webhooks with kloudless. I downloaded ngrok and set a URL to point to a local server and then setup a server using Python -m SimpleHTTPServer 8080. I ran POST requests with the URL ngrok gave me and was able to see/navigate my local directories. I want to use this script to verify the webhook sender and launch a task.

#!/usr/bin/env python
from flask import Flask, request, abort

import hmac
import base64
import hashlib
import threading

app = Flask('demo_app')
APP_ID = ''
API_KEY = ''
@app_route('/webook', methods=['POST'])     //FIX. @app_route should be @app.route
def receiver():
# Verify the Request Signature
digest = hmac.new(API_KEY,msg=request.data,digestmod=hashlib.sha256).digest()
sig = base64.b64encode(digest)
if not sig == request.headers.get('X-Kloudless-Signature'):
abort(403)

# Since the request is verified we can actually do something
account_id = request.form.get('account')
if account_id:
    threading.Thread(target=process_account, args=(account_id,)).start()
# In order to verify that the endpoint is alive you should always return your application id with a 200 OK response
    return APP_ID

if __name__ == 'main':
    app.run()

I'm getting an error

@app_route('/webhook ', methods=['POST']) NameError: name 'app_route' is not defined

Do I specify the URL that ngrok set up using localhost for the @app_route?

UPDATE

the @app_routeshould be left as /webhook the external URL should be the https://046f3f46.ngrok.io/webhook as an example. Now I'm trying to figure why after I added this external URL to my dev portal under current webhooks, it is giving me an unsupported POST method when clearly the app supports it.

UPDATE

So the Python SimpleHTTPSever does not support the POST method. I have found that this python server does support the GET and POST methods(well it's supposed to), however I'm getting a 405 error code which again is an unsupported method. Not sure what's going on, it has to be something in the environment.

DJ2
  • 1,721
  • 3
  • 34
  • 74
  • 2
    Apologies for the error in the blog post. We'll get on fixing that. Could you try this for the webhooks receiver: https://gist.github.com/vinodc/ee4933114e988bc02995 It should support both GET and POST Note that I am using `app.route` and not `app_route`. You can then add in signature validation as you have done above. – vinod Jan 06 '17 at 06:26
  • Thank you for looking into this. The basic webhook receiver gist you posted works perfectly. I'm attempting to add in the signature verification and getting a key error message in my local webserver when adding the ngrok URL to my dev portal in kloudless. Looking into it, any ideas ? @vinod – DJ2 Jan 06 '17 at 15:18
  • So when this line is returned os.environ["APP_ID"] it's giving a key error. I changed it to return the hard coded APP_ID, and then was able to add my ngrok/webhook URL to the dev portal and got the 200 Ok response. when entered into chrome it returns the APP_ID. will build form here @vinod – DJ2 Jan 06 '17 at 16:14
  • Also, trying to test using the cloud-text-editor I get an error when trying to save a test text file, when i choose whatever account(gdrive, onedrive, etc.) it gives me `TypeError: create() got an unexpected keyword argument 'parent_id'` @vinod – DJ2 Jan 06 '17 at 20:24
  • still haven't had any luck with saving a file with cloud-text-editor @vinod – DJ2 Jan 11 '17 at 16:56
  • 1
    I've updated the cloud text editor example app to use the latest SDK and authenticator library correctly, removing incompatibilities. Could you check out the project now? Thanks. – vinod Jan 12 '17 at 03:12
  • It now runs smoothly and the `test.txt` file uploads to cloud storage of my choosing, is there a way that I could rework the js file to upload a file to multiple/all of the my connected storage accounts with one reques? @vinod – DJ2 Jan 12 '17 at 18:56
  • Can that change be made to the js authenticator library or should it be done elsewhere? @vinod – DJ2 Jan 12 '17 at 19:06

0 Answers0