Skip to main content

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 

Made with ❤ on top of the X-Model and Aiogram.

Metadata

Release files for xtg-auth 0.0.19

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xtg-auth 0.0.19
File Size Uploaded
xtg_auth-0.0.19.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xtg-auth 0.0.19
File Interpreter ABI Platform
xtg_auth-0.0.19-py3-none-any.whl Python 3 none any Details

Total release size: 10.2 kB

Release files / xtg_auth-0.0.19.tar.gz

Download URL xtg_auth-0.0.19.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e990b48b802cf4e67e380efb4cc8dfe2438ea5c095214ced18c3b2e677faca33
BLAKE2b-256 checksum
How to use checksums
6207a50e936846ad90d290be3875a8481fb15691ca934b921e215ccd19defbe9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.9

Release files / xtg_auth-0.0.19-py3-none-any.whl

Download URL xtg_auth-0.0.19-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1dac0eff3c9a4d5cabdc626902a5a767db66c5c6864a196a2123e11f241a5fc7
BLAKE2b-256 checksum
How to use checksums
f71d0b1732e3bee497f88aae0ddb566955a88af0b3913a5c6b861571f5495b0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.9
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page