This repository contains Python code and tests for verifying the authenticity of users interacting with a Telegram Mini App. The core logic is based on Telegram's official guidelines for validating data received from Telegram.WebApp.initData
.
- 🔒 HMAC-SHA256 validation of the Mini App payload using the bot token
- ⏱️ Optional check to ensure the data is not outdated (
auth_date
) - ✅ Unit tests to ensure the integrity of the verification logic
- 📦 Minimal dependencies, can be easily integrated (some of the code uses sanic-api, but can be rewritten easily)
git clone https://github.com/PhillMckinnon/telegram-verify-sanic-api.git
cd telegram-verify-sanic-api
pip install -r requirements.txt
remove the .example extension from the .env file,
Add your bot token into the .env file
python -m pytest
test_verify_valid_data
: Valid data with a correct hash and timestamptest_verify_invalid_hash
: Payload with a tampered or incorrect hashtest_verify_missing_hash
: Missinghash
parameter in the datatest_verify_expired_auth_date
: Data with an outdatedauth_date
timestamp
This project is licensed under the terms of the MIT License.
For questions, feedback, or collaboration, feel free to reach out:
- 📧 Email: phillipmckinnonwork@proton.me
- 🐙 GitHub: @PhillMckinnon