Skip to content
TGWAY
Channels & Bots STEP 65 / 99

Add Log In With Telegram to Your Site (OpenID Connect)

Telegram login now uses OpenID Connect. Register URLs in @BotFather, keep the Client Secret on your server, exchange the code and verify the ID token.

  • Applies toDevelopers
  • LevelL4
  • Reading time4 min
  • Verified

The short answer

  1. 1Telegram login is now standard OpenID Connect with PKCE, set up through a bot in @BotFather.
  2. 2Register allowed URLs, take the Client ID and Secret, and keep the Secret on your server.
  3. 3Exchange the code server-side and verify the ID token's signature before trusting it.
In this article
  1. What "Log in with Telegram" is now
  2. Setting it up
  3. The flow, if you implement it yourself
  4. What you can ask for
  5. FAQ
  6. At a glance

What "Log in with Telegram" is now

A "Log in with Telegram" button lets visitors sign in to your site or app with their Telegram account instead of creating a new password. Telegram now documents this as an OpenID Connect flow, the same standard used by other "sign in with" buttons: the authorization code flow, with PKCE. The older iframe JavaScript widget's documentation has been moved to an archive page.

ItemDetail
You needA bot to represent your service, created with @BotFather
You getA Client ID and a Client Secret, from the bot's Login Widget settings
You registerThe allowed URLs: your site's origins and the redirect URIs users return to
Ways to add itThe official web library, official iOS and Android SDKs, or standard OpenID Connect by hand

Setting it up

  1. Create or pick a bot in @BotFather; see creating a bot with BotFather. Its name and photo appear on the login prompt as if they were your service's, so make them recognisable.
  2. Register your allowed URLs in the bot's Login Widget settings. Login does not open from addresses you have not registered.
  3. Copy the Client ID and Client Secret shown there.
  4. Add the button with the official library, or follow the flow below if you implement it yourself.

The flow, if you implement it yourself

  1. Send the user to Telegram. The browser goes to oauth.telegram.org with your client ID, redirect URI, the scopes you want, a state value against forged requests and a PKCE challenge.
  2. They come back with a code. If the user agrees, Telegram redirects to your URI with a one-time code.
  3. Exchange it on your server. Your server sends the code, the PKCE verifier and your client credentials to the token endpoint and receives an ID token and an access token. This step must happen server-side.
  4. Verify before you trust. Check the ID token's signature against Telegram's published keys (JWKS), and that the issuer is Telegram, the audience is your bot, and it has not expired. Only then use what it says about the user.

Telegram has no separate UserInfo endpoint, so some OpenID Connect libraries need to be told not to ask for one; the user data comes in the ID token.

What you can ask for

ScopeWhat it gives you
openidRequired. A stable identifier for the user
profileBasic details such as name, username and photo
phoneThe verified phone number, only if the user agrees
telegram:bot_accessPermission for your bot to send the user direct messages

Ask only for what you use. Users can refuse the phone number and the bot permission, so sign-in should still work without them. The last scope is the one way a user lets your bot message them first, which bots otherwise cannot do; see bot accounts vs user-account automation.

FAQ

How does Log In With Telegram work for websites now?

It uses OpenID Connect. You register a bot in @BotFather, send users to oauth.telegram.org, exchange the returned code on your server and verify the ID token.

Where do I get the Telegram login Client ID and Secret?

In @BotFather, in your bot's Login Widget settings, after registering your allowed URLs.

Can my bot message users who logged in with Telegram?

Only if they grant the telegram:bot_access scope during login.

Sources

Summary

At a glance

Add Log In With Telegram to Your Site (OpenID Connect) — at a glance illustration
  1. 1Setup

    Bot's Login Widget: URLs, Client ID, Secret.

  2. 2Flow

    Redirect, code, server exchange, verify ID token.

  3. 3Scopes

    openid, profile, phone, telegram:bot_access.

Share this guide

Send it to a friend who has the same question.

Telegram WhatsApp
More

Open on your phonePoint your phone camera here to open this guide.

Updated

Related articles

View all ›