How to Add Telegram Login to the Website with new OIDC Flow
I wrote about adding Telegram Login without relying on the old embedded widget.
The article walks through Telegram's newer OpenID Connect flow and shows how to keep the UI fully custom while the backend handles the sensitive OAuth parts.
The PoC covers:
- Creating and configuring a Telegram bot for OIDC login.
- Generating
state,codeVerifierandcodeChallengefor PKCE. - Redirecting users to Telegram's OAuth endpoint.
- Exchanging the callback
codefor tokens on the server. - Reading Telegram user data from
id_token. - Creating a simple session and rendering logged-in / logged-out UI.
The example is intentionally small: one Bun TypeScript server, an in-memory OAuth state store and a lightweight cookie session.
It is good for understanding the flow, but production needs proper id_token verification, signed or encrypted cookies, HTTPS-only secure cookies and shared storage for state/session in multi-instance setups.
If you want to read the full walkthrough, check my Medium post: https://kulikovd.medium.com/how-to-add-telegram-login-to-the-website-with-new-oidc-flow-4a1bb8ad03c4