🚀 A Rust-based Python package for validating Telegram WebApp authorization.
Project description
🦀🐍 Telegram WebApp Auth Library
This library is a simple way to authenticate users in your web application using Telegram.
Example
For a complete example, check out the Example Bot repository.
Installation
Using pip
pip install teleapp-auth
Using Poetry
poetry add teleapp-auth
Using pipenv
pipenv install teleapp-auth
Using uv
uv pip install teleapp-auth
Usage
from fastapi import Request, FastAPI
from teleapp_auth import get_secret_key, parse_webapp_data, validate_webapp_data
app = FastAPI()
secret_key = get_secret_key("BOT_TOKEN")
@app.post("/check_data")
async def check_data(request: Request) -> bool:
request_json = await request.json()
auth_data = request_json.get("auth_data") # Telegram auth data from the request
webapp_data = parse_webapp_data(auth_data) # Parse the auth data to the WebAppInitData object
# Example of the parsed data:
# WebAppInitData {
# query_id: "AAEt6-JYAAAAAC3r4lj2oADQ",
# user: WebAppUser {
# id: 1,
# is_bot: None,
# first_name: "Test",
# last_name: "",
# username: "test",
# language_code: "ru",
# is_premium: None,
# added_to_attachment_menu: None,
# allows_write_to_pm: true,
# photo_url: None
# },
# receiver: None,
# chat: None,
# chat_type: None,
# chat_instance: None,
# start_param: None,
# can_send_after: None,
# auth_date: 1726572911,
# hash: "f87a5a37a5b487700a35cb1e3d2e92afa67e4b67066c9f1fa2c34986c2350b6e
# }
return validate_webapp_data(webapp_data, secret_key) # True if the data is valid, False otherwise
FAQ
1. What is the purpose of this library?
This library simplifies the process of authenticating users in your web application using Telegram WebApp authentication.
2. Can I get the user's profile photo with this library?
The photo_url
field in the authentication data contains a URL to the user's profile photo. However, it is only available for Mini Apps launched from the attachment menu. Currently, integration with the attachment menu is only accessible to major advertisers on the Telegram Ad Platform. All bots can still test this feature in the test server environment by contacting Botfather on the test server.
3. Does this library automatically handle sending authentication data to my server?
No, you need to handle the process of sending the authentication data to your server. You can find an example of how to do this in the page.html file within the examples directory.
4. How do I validate the authentication data?
Use the validate_webapp_data
function from the library to verify the authenticity of the data. This function compares the data with a secret key derived from your bot's token.
5. Can I use this library with any Python web framework?
Yes, the library is framework-agnostic, though examples are provided with FastAPI and Blacksheep. You can adapt it to other frameworks with minimal effort.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file teleapp_auth-1.0.1.tar.gz
.
File metadata
- Download URL: teleapp_auth-1.0.1.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0439a569789f97cf93f1893bfe8a6b95d1b60abf452fe010e5bbc0ccedf80ef2 |
|
MD5 | 727c99586d281d8f782e96dfb70899a8 |
|
BLAKE2b-256 | a070d629b273ce74b57b0f566c6890be080cf6ae0881b8a3deb58ea1afaf64a6 |
File details
Details for the file teleapp_auth-1.0.1-cp312-none-win_amd64.whl
.
File metadata
- Download URL: teleapp_auth-1.0.1-cp312-none-win_amd64.whl
- Upload date:
- Size: 157.9 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6242fce914d834fd422ed9b42cd6ee159300b27dd8330d3c6dbb5a12a1ddab3 |
|
MD5 | 1a9117ef362816d859dff940f80165b7 |
|
BLAKE2b-256 | a1d676da320cf1963aa29e77596647169d7a03c6d50503df0641dcc2b6a5a265 |
File details
Details for the file teleapp_auth-1.0.1-cp312-cp312-manylinux_2_34_x86_64.whl
.
File metadata
- Download URL: teleapp_auth-1.0.1-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 251.8 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a6ab50e0bd4fee7855b90c2d4af6d535290bef2ec6b625ff19f13dcea95779d |
|
MD5 | c1dfd8364d02541ccca0fc17fe9a377a |
|
BLAKE2b-256 | c0bd0df24afe5e4d7d7aaeffc863540634e1a1a6d9f3ba21d55c53766e86f697 |
File details
Details for the file teleapp_auth-1.0.1-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: teleapp_auth-1.0.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 219.1 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4a511bbf4464002ff033beeadaca8053e4ec962db2a7a3a25be6aa9d405e8f0 |
|
MD5 | 7038d53f1c78830fc888057a5cd55fa9 |
|
BLAKE2b-256 | 4b89c015548bfbe1923b82023f5c9f920b323e9a2784bb6bb5886194ed95f4a4 |
File details
Details for the file teleapp_auth-1.0.1-cp311-none-win_amd64.whl
.
File metadata
- Download URL: teleapp_auth-1.0.1-cp311-none-win_amd64.whl
- Upload date:
- Size: 158.7 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 515528f57a60f36357938ab9e5e624e861c86da1a61f265456b432f474682064 |
|
MD5 | f1dcb3fffce392a927d3001e7ef21823 |
|
BLAKE2b-256 | 79ee9becf9c04099dcf55f3b914555ff54541aafb03b6c9c46d0eb3eb99b3ce3 |
File details
Details for the file teleapp_auth-1.0.1-cp311-cp311-manylinux_2_34_x86_64.whl
.
File metadata
- Download URL: teleapp_auth-1.0.1-cp311-cp311-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 252.5 kB
- Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e159f1d2cba2bb9be9e8f320b4bbeac37d63bc4a19fb0852313becd4af741da |
|
MD5 | 81f912462d4c65bb16cb217c7cb6cd88 |
|
BLAKE2b-256 | 8f575e21e37a14c1b55265de5abf3b66e799017f937a9ccddd38f37e63f99d0f |
File details
Details for the file teleapp_auth-1.0.1-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: teleapp_auth-1.0.1-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 219.8 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f96ba9fd70eb4bac889a232f246641d24c66694d87079864a55a7940f8c7430 |
|
MD5 | f491933f1ed1c0cb8f7bf48714bacd15 |
|
BLAKE2b-256 | b543ee36ec6ed1f6fd5bef8d18bcc559cf8f2e4d8f1f96a37ebce06273a24a03 |
File details
Details for the file teleapp_auth-1.0.1-cp310-none-win_amd64.whl
.
File metadata
- Download URL: teleapp_auth-1.0.1-cp310-none-win_amd64.whl
- Upload date:
- Size: 158.8 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdf41c8034deda88b8954eed3d463f6c501d3b933d6c87c7001776548d018b52 |
|
MD5 | cd0d1b0a41ed8dca1c333e87106ee9dc |
|
BLAKE2b-256 | dbb4264f96bc149d953c582d41a67a579f445000def8938a44795dc2350762ce |
File details
Details for the file teleapp_auth-1.0.1-cp310-cp310-manylinux_2_34_x86_64.whl
.
File metadata
- Download URL: teleapp_auth-1.0.1-cp310-cp310-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 252.7 kB
- Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 556be146b5e930eb428aeb6f2ec8d3b26e9e70b97df362e466ddcde4698af0ea |
|
MD5 | babc59bf8228544064e5ab8659f0e213 |
|
BLAKE2b-256 | 3980f4e543b208ad4e27f4e907519f87b2433bdd4ed24ce6510fd5749bca3c3d |
File details
Details for the file teleapp_auth-1.0.1-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: teleapp_auth-1.0.1-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 219.9 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da3a03d482eb9375a501f075a96c5b61dbae2879cc7cf6b34377d2981f3b69bd |
|
MD5 | e59602765c052797125baba3f9bfb925 |
|
BLAKE2b-256 | 4103a195cb6d243b5c37907bd7e5ebd6f8de362af7eca97512a250efada84daf |
File details
Details for the file teleapp_auth-1.0.1-cp39-none-win_amd64.whl
.
File metadata
- Download URL: teleapp_auth-1.0.1-cp39-none-win_amd64.whl
- Upload date:
- Size: 159.4 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9d438ff48a0f6c303126fdb18ea41fe20432f7088fdb459eda71a44ab3aa8d5 |
|
MD5 | 3e5db38587df0dec824789390c6219bb |
|
BLAKE2b-256 | fe18840d025033277ac2b20a4bec60d98ad98fd464486e9c3eb7e6a4956b3035 |
File details
Details for the file teleapp_auth-1.0.1-cp39-cp39-manylinux_2_34_x86_64.whl
.
File metadata
- Download URL: teleapp_auth-1.0.1-cp39-cp39-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 253.1 kB
- Tags: CPython 3.9, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34d8d78d881839466b18dfeba5e659bdf3fc6fb2d8729e95fc7f5f38dc11a6ae |
|
MD5 | a9099b6dbf59976898a68e8699fb7cbc |
|
BLAKE2b-256 | 32407d761934006d1ea4966a5b17eb7727390a8f3f8623edd02cbd0335b02788 |
File details
Details for the file teleapp_auth-1.0.1-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: teleapp_auth-1.0.1-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 220.3 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ca8726bab27620bb2438ac89d74402b9ec040671653eb0f9fe16ab7072bdbd0 |
|
MD5 | 2eb9e277812619d90ed7448e7373b9f2 |
|
BLAKE2b-256 | 61e2c79dab7c657a0bae64908a2039881a2dabacc6bb6e66ec484b59a946cf27 |