Skip to main content

pyTelegramOIDC

PyPI - Version Python Versions License

pyTelegramOIDC — is a modern, fully asynchronous Python library for integrating the official Telegram Login (OpenID Connect) into your web applications.

It strictly follows standard OIDC specifications, supports PKCE (Proof Key for Code Exchange), and natively extracts all user data (including phone numbers) directly from cryptographically signed ID Tokens.

Features

  • Fully Async: Uses httpx for non-blocking HTTP requests.
  • Secure: Validates JWT signatures automatically using Telegram's official JWKS keys.
  • Pydantic Models: Strict typing for user profiles and tokens out of the box.
  • Phone Number Support: Easily extract requested user phone numbers.

Installation

You can install the library via pip:

pip install pyTelegramOIDC

Note: Although you install it via pyTelegramOIDC, the module is imported as teleoidc (similar to how pyTelegramBotAPI is imported as telebot).

Quickstart (JS Widget Flow)

If you are using the official Telegram JS Popup Widget, your frontend will receive an id_token. Use teleoidc to validate it and get the user's data safely.

from teleoidc import TelegramAsyncOIDCClient

# 1. Initialize the client
client = TelegramAsyncOIDCClient(
    client_id="YOUR_BOT_ID",        # From @BotFather
    client_secret="YOUR_BOT_SECRET", # From @BotFather
    redirect_uri="https://yoursite.com/auth/callback"
)

# 2. Validate the token received from the frontend
id_token = "eyJhbGciOiJSUzI1NiIs..." # Token from Telegram JS

try:
    user = client.validate_id_token(id_token)
    
    print(f"Logged in as: {user.name} (@{user.preferred_username})")
    print(f"Telegram ID: {user.id}")
    
    if user.phone_number:
        print(f"Phone: {user.phone_number}")

except Exception as e:
    print(f"Invalid token: {e}")

Manual OAuth2 Redirect Flow

If you are doing a full backend redirect instead of the JS widget, pyTelegramOIDC provides native methods to generate auth links and exchange codes for tokens (get_auth_request and exchange_code_for_token).

License

MIT License

Metadata

Release files for pyTelegramOIDC 1.0.0

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

Source distribution (sdist)

Source distribution for pyTelegramOIDC 1.0.0
File Size Uploaded Provenance Actions
pytelegramoidc-1.0.0.tar.gz 6.2 kB Without provenance Details for pytelegramoidc-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyTelegramOIDC 1.0.0
File Interpreter ABI Platform Actions
pytelegramoidc-1.0.0-py3-none-any.whl Python 3 none any Details for pytelegramoidc-1.0.0-py3-none-any.whl

Total release size: 13.4 kB

Release files / pytelegramoidc-1.0.0.tar.gz

Download URL pytelegramoidc-1.0.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d67a832dafa2ca585e106a1d9887f3477503e7bc83e4a6d9fdfffbd3f2783ccd
BLAKE2b-256 checksum
How to use checksums
b0817d5d95596905689d43e3b9f06b6934f4dd7e5aaaae582ffed2e92dfde85b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / pytelegramoidc-1.0.0-py3-none-any.whl

Download URL pytelegramoidc-1.0.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e8af5e4510a220bf1adebd633f7823dab9bb2b32f732b2993f6ff768d4dd26b
BLAKE2b-256 checksum
How to use checksums
5bc869e0154fdbbe1ec33d344f5b348c888725502e24c9ea3821e75aa5ada066
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Security for pyTelegramOIDC 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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