twilio / twilio/twilio-python

Twilio authentication always fails

Open
#715 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority: medium status: help wanted type: question
Dominant language
Python
Stars
2.1k
Forks
815
Avg merge
2d 13h
Merged PRs (30d)
2

Description

Issue Summary

I am developing a Python (Flask) voice app on a local machine and using Ngrok tunnel to allow Twilio access the app via a webhook (all set up according to the Twilio guide). I need to add a step to check the requests are coming from Twilio and am using the RequestValidator from the Twilio Python SDK. However, this step always returns false, but should be true as I am the one initiating the request during testing.

Steps to Reproduce
  1. Set up a test voice application with Python Flask, and using Ngrok tunnel
  2. Get the host, request url and scope
  3. Run RequestValidator()
Code Snippet

In your Python Flask test voice application, set up a /call app route, then inside the call() test the following

validator = RequestValidator(TWILIO_AUTH_TOKEN)

path = request.path
headers = dict(request.headers)
host = headers.get('Host')
url = f"http://{host}{path}"
body = request.data

validator.validate(request.url, headers, body)
Technical details:
  • twilio-python version: 8.1.0
  • python version: 3.8.8
  • Flask version: 2.2.2
  • pyngrok version: 6.0.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Flask /call route and the RequestValidator usage shown in the issue, checking how request.url, the Host header, path, and request body are constructed through the Ngrok request. Reproduce the validation result with the listed Python, Flask, and twilio-python versions, then confirm that a genuine test request validates successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
api, authentication, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.