Skip to content
Dmitry Vasiliev edited this page Aug 28, 2024 · 2 revisions

module auth


function generate_secret_key

generate_secret_key(token: str) → bytes

Generates a secret key from a Telegram token.

Links: https://core.telegram.org/bots/webapps#validating-data-received-via-the-mini-app

Args:

  • token: Telegram Bot Token

Returns:

  • bytes: secret key

class TelegramUser

Represents a Telegram user.

Links: https://core.telegram.org/bots/webapps#webappuser

method __init__

__init__(
    id: int,
    first_name: str,
    is_bot: bool | None = None,
    last_name: str | None = None,
    username: str | None = None,
    language_code: str | None = None,
    is_premium: bool | None = None,
    added_to_attachment_menu: bool | None = None,
    allows_write_to_pm: bool | None = None,
    photo_url: str | None = None
) → None

class TelegramAuthenticator

method __init__

__init__(secret: bytes)

method verify_token

verify_token(token: str) → TelegramUser

Verifies the data using the method from documentation. Returns Telegram user if data is valid.

Links: https://core.telegram.org/bots/webapps#validating-data-received-via-the-mini-app

Args:

  • hash_: hash from init data
  • token: init data from webapp

Returns:

  • TelegramUser: Telegram user if token is valid

Raises:

  • InvalidInitDataError: if the token is invalid

This file was automatically generated via lazydocs.