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.1.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.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: telegram_webapp_auth-3.1.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-1015-azure

File hashes

Hashes for telegram_webapp_auth-3.1.0.tar.gz
Algorithm Hash digest
SHA256 cfe934cc2459d6ca0f849125ad6fe84c2d8b1b58de296bb1320a8688fd35bcbd
MD5 001e2315824be939eace11e881d83145
BLAKE2b-256 1170e85327232a847d0e9200ed61308e34a780a240a3bbd167fe0fd8998f972d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: telegram_webapp_auth-3.1.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-1015-azure

File hashes

Hashes for telegram_webapp_auth-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d192c2e571f74301139081fca92511428c5955bce43c0ce2e3ed64e71710ffe8
MD5 ef516a1f6ba2076a5942dea7712a7b7e
BLAKE2b-256 e974e0a641fb2210460dc829dffcc091f4bd9fac67a7ed16f0673d9ddf457b5a

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