Skip to main content

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 

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xtg_auth-0.0.13.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

xtg_auth-0.0.13-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file xtg_auth-0.0.13.tar.gz.

File metadata

  • Download URL: xtg_auth-0.0.13.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for xtg_auth-0.0.13.tar.gz
Algorithm Hash digest
SHA256 d42f15af85dea54a5de00b62569e0b5b044c3d91a552152843ec0ed7589b0177
MD5 317f1440c3d878d2492b2c7de81e4952
BLAKE2b-256 59cdc7baea0f9edf8aad0a20b0cb348a1c00c0746a2d46d07c5f128f985007c9

See more details on using hashes here.

File details

Details for the file xtg_auth-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: xtg_auth-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for xtg_auth-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 a2e40f2e990a3e897e41205251d43d00c9cdf343c29a9f928c33886755fec64e
MD5 be640489fe5dbfc8e28a34fa04fb5f08
BLAKE2b-256 0ce183854e94a97c7d8dfd9c5ca56ddbf1b26e2f2bd15560dbe572f9ca86abe8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page