Authentication backend for Telegram Mini Apps on starlette/fastapi API
Project description
Telegram Auth Backend for FastAPI/Starlette
INSTALL
In your FastAPI/Starlette app:
pip install xtg-auth
Add your Telegram Bot API Token to .env file as TgBotToken:
TgBotToken=0000000000:AAaaaAaAAAaaAAAAaaAAAaAAAaaAaaaaaAA
Before running add AuthenticationMiddleware to your app, and set TgAuth object with passed token as backend
from fastapi import FastAPI
from starlette.middleware.authentication import AuthenticationMiddleware
from tg_ath import TgAuth
app = FastAPI()
TOKEN = env('TgBotToken')
app.add_middleware(AuthenticationMiddleware, backend=TgAuth(TOKEN))
Using:
Protected endpoints expect Telegram.WebApp.initData string in Authorization header afrer Tg prefix in each request.
example:
Authorization: Tg user=%7B%22id%22%3A1038938370%2C%22first_name%22%3A%22Crypto%E2%86%94%EF%B8%8FFiat%22%2C%22last_name%22%3A%22%F0%9F%92%B5%F0%9F%92%B6%F0%9F%92%B3%22%2C%22username%22%3A%22ex212%22%2C%22language_code%22%3A%22en%22%2C%22allows_write_to_pm%22%3Atrue%7D&chat_instance=-6786124926491770465&chat_type=sender&auth_date=1729138692&hash=32e367eb6019007fdb2bd8f9a08628fb14ebc737df4a0dad3ecd2910b342f488
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 Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xtg_auth-0.0.19.tar.gz.
File metadata
- Download URL: xtg_auth-0.0.19.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e990b48b802cf4e67e380efb4cc8dfe2438ea5c095214ced18c3b2e677faca33
|
|
| MD5 |
31b4b84b164542526aae44072317ce77
|
|
| BLAKE2b-256 |
6207a50e936846ad90d290be3875a8481fb15691ca934b921e215ccd19defbe9
|
File details
Details for the file xtg_auth-0.0.19-py3-none-any.whl.
File metadata
- Download URL: xtg_auth-0.0.19-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1dac0eff3c9a4d5cabdc626902a5a767db66c5c6864a196a2123e11f241a5fc7
|
|
| MD5 |
b838ebb7bd2816d08f135a7662f117b0
|
|
| BLAKE2b-256 |
f71d0b1732e3bee497f88aae0ddb566955a88af0b3913a5c6b861571f5495b0c
|