Skip to main content

Python package that implements Telegram Mini Apps authentication algorithms.

Project description

telegram-webapp-auth

telegram-webapp-auth

telegram-webapp-auth validates Telegram Mini App initData in Python.

It implements Telegram's official Mini Apps authentication algorithms, supports both bot-token and third-party validation flows, and returns typed dataclasses for users, chats, and init data.

Features

  • Bot-token validation with TelegramAuthenticator.validate()
  • Third-party Ed25519 validation with TelegramAuthenticator.validate_third_party()
  • Optional expiry checks with expr_in
  • Typed WebAppInitData, WebAppUser, and WebAppChat results, with unknown top-level fields preserved
  • Python 3.10+ support
  • Lightweight runtime dependency set

Installation

pip install telegram-webapp-auth
# or
poetry add telegram-webapp-auth
# or
uv add telegram-webapp-auth

Quick Start

from datetime import timedelta

from telegram_webapp_auth.auth import TelegramAuthenticator
from telegram_webapp_auth.auth import generate_secret_key
from telegram_webapp_auth.errors import ExpiredInitDataError
from telegram_webapp_auth.errors import InvalidInitDataError

secret_key = generate_secret_key("123456:ABC-DEF")
authenticator = TelegramAuthenticator(secret_key)

try:
    init_data = authenticator.validate(
        init_data=request.headers["Authorization"],
        expr_in=timedelta(minutes=5),
    )
except ExpiredInitDataError:
    raise PermissionError("Telegram init data has expired")
except InvalidInitDataError:
    raise PermissionError("Telegram init data is invalid")

telegram_user = init_data.user

Documentation

Read the full documentation at swimmwatch.github.io/telegram-webapp-auth.

Useful starting points:

Maintenance And Security

This project is in maintenance mode and accepts bug fixes. Please report security issues privately; see SECURITY.md.

License

telegram-webapp-auth is licensed under the MIT License.

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

telegram_webapp_auth-3.2.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

telegram_webapp_auth-3.2.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file telegram_webapp_auth-3.2.0.tar.gz.

File metadata

  • Download URL: telegram_webapp_auth-3.2.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.17.0-1018-azure

File hashes

Hashes for telegram_webapp_auth-3.2.0.tar.gz
Algorithm Hash digest
SHA256 5bcb17e3258384f73bca4fdfc8c7b523931a0672ff200cdd565bd5cca3ebfc77
MD5 70077ea20753284b530468dda8ce1ac8
BLAKE2b-256 061da7a1c760a65674e96c615f4a5e9b65dd7835afba983b85adfe810e2ad5b6

See more details on using hashes here.

File details

Details for the file telegram_webapp_auth-3.2.0-py3-none-any.whl.

File metadata

  • Download URL: telegram_webapp_auth-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.17.0-1018-azure

File hashes

Hashes for telegram_webapp_auth-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 281c4535c457634f7ab7340e06002ef9e38fe5b618dc0a673410f8e7218c279b
MD5 44420aac67009734fbce843487583161
BLAKE2b-256 3a496fd9d4b37a83ef806f52ffc802e1957daf802cd2204c6ce16d33376a3932

See more details on using hashes here.

Supported by

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