Spaces:
Running
on
Zero
Running
on
Zero
sd
Browse files- mysite/asgi.py +7 -0
mysite/asgi.py
CHANGED
@@ -629,6 +629,13 @@ CHANNEL_SECRET = os.getenv('CHANNEL_SECRET')
|
|
629 |
CHANNEL_ACCESS_TOKEN = os.getenv('CHANNEL_ACCESS_TOKEN')
|
630 |
WEBHOOK_URL = os.getenv('WEBHOOK_URL')
|
631 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
632 |
@app.post("/webhook")
|
633 |
async def webhook(request: Request):
|
634 |
try:
|
|
|
629 |
CHANNEL_ACCESS_TOKEN = os.getenv('CHANNEL_ACCESS_TOKEN')
|
630 |
WEBHOOK_URL = os.getenv('WEBHOOK_URL')
|
631 |
import requests
|
632 |
+
|
633 |
+
def validate_signature(body: str, signature: str, secret: str) -> bool:
|
634 |
+
hash = hmac.new(secret.encode('utf-8'), body.encode('utf-8'), hashlib.sha256).digest()
|
635 |
+
expected_signature = base64.b64encode(hash).decode('utf-8')
|
636 |
+
return hmac.compare_digest(expected_signature, signature)
|
637 |
+
|
638 |
+
|
639 |
@app.post("/webhook")
|
640 |
async def webhook(request: Request):
|
641 |
try:
|