v5.14.0
This release of the Nylas Python SDK brings a couple of new features.
Release Notes
Added
- Added support for verifying webhook signatures (#257)
- Added optional parameter for token-info endpoint (#256)
Verifying webhook signatures
from flask import Flask, request, jsonify
from nylas import APIClient, Webhook
import os
import json
app = Flask(__name__)
port = 9000
NYLAS_CLIENT_SECRET = os.environ.get("NYLAS_CLIENT_SECRET")
@app.route("/", methods=["POST"])
def webhook_callback():
signature = request.headers.get("X-Nylas-Signature")
request_data = json.dumps(request.get_json())
if not Webhook.verify_webhook_signature(signature, request_data, NYLAS_CLIENT_SECRET):
return jsonify({"error": "Invalid signature"}), 403
body = request.json
print("Webhook event received: ", json.dumps(body))
return jsonify({"success": True}), 200
if __name__ == "__main__":
app.run(port=port)