Telegram Auth

This guide explains how to let players sign in from a Telegram Mini App using the telegram-auth plugin, displayed in the admin panel as Telegram Mini App Auth.

The plugin (version 2.0) adds Telegram as a login provider. It verifies the initData that Telegram gives the Mini App; the engine then signs in the linked player, creates a new account, or asks for the player’s two-factor code, exactly as for any other login provider.

Upgrading from 1.0? Existing Telegram players keep their accounts: their links were copied to the engine’s sign-in methods. The plugin’s own API routes and its Telegram Accounts admin page are gone; linked accounts are managed on the engine’s generic screens (see Admin). 2.0 asks you to grant the Sign players in (auth:provider) permission on upgrade. An installed 1.0 keeps working on this engine version until plugin API 1.5. Details: docs/plugins/TELEGRAM_AUTH.md.

Enabling the Plugin

Telegram Mini App Auth is sold separately on onlinepokerscript.com; Poker Engine releases don’t include it. You install the .tgz archive you received with it like any other plugin.

  1. Download the plugin’s .tgz archive for your Poker Engine version.
  2. In the admin sidebar, go to Extensions › Plugins and click Upload plugin, then choose the file.
  3. Click Activate on Telegram Mini App Auth and grant the requested permission.
  4. Click Settings on its row and enter the Bot Token.
  5. In Telegram, point your bot’s Mini App at https://<your-host>/plugins/telegram-auth/public/mini-app.

Required permission: Super-admin for upload, activate, and saving settings. See Plugin Management.

Telegram appears under Settings › Login Providers once the plugin is active, and is enabled as soon as a valid bot token is saved. It has no button on the login page outside Telegram: Continue with Telegram appears only when the page is open inside Telegram.

Settings

SettingKeyDefaultDescription
Bot TokenbotTokenNoneUsed to verify initData. Encrypted at rest. Telegram sign-in is off until it is set.
InitData Max Age (seconds)maxInitDataAgeSeconds300How old an initData payload may be (30 to 86400).
Allow Auto-ProvisioningallowAutoProvisionOnCreate an account on first Telegram sign-in. Off: only players who linked Telegram can use it.
Username PrefixusernamePrefixtg_Fallback prefix for generated usernames. Up to 16 letters, numbers, and underscores.
Bot UsernamebotUsernameEmptyOptional public bot username.

Allow Auto-Provisioning sets the provider’s sign-up mode (auto when on, link_only when off). A sign-up mode chosen for Telegram on the Login providers page overrides it.

Bot Token

The token must look like 123456:ABC..., otherwise saving is rejected. After a save, the server calls Telegram getMe with a 5-second timeout and logs the result. A failed call only logs a warning and does not block the save, so check the server log after changing the token.

Init-Data Checks

Telegram stamps each initData payload with an auth_date and signs it with your bot token. A payload is refused when:

  • it is over 8 KB, has duplicate keys, or lacks hash, auth_date or valid user data;
  • auth_date is older than InitData Max Age or more than 60 seconds in the future;
  • the HMAC-SHA256 signature does not match the bot token;
  • the same payload was already used within the freshness window (setting a first password is the one exception, see below).

Every refusal answers CREDENTIAL_INVALID (401); the reason is written to the server log. Players who see "Telegram could not confirm this session" should close and reopen the Mini App.

Replay protection is held in Redis when Redis is enabled, and otherwise in the memory of each server process. On a multi-node deployment, enable Redis so that a payload used on one node can’t be replayed on another.

Sign-In Behaviour

Once initData is verified, the engine’s rules for every login provider apply:

SituationResult
No linked account, Allow Auto-Provisioning off (or registration closed)EXTERNAL_AUTH_NOT_LINKED (403)
Account in an admin groupEXTERNAL_AUTH_ADMIN_FORBIDDEN (403): admins use their password and admin 2FA
Account blocked or frozenAUTHENTICATION_ERROR (401)
Account awaiting manual approval, or an unconfirmed email your approval method requiresThe player sees the matching message
Too many sign-in requestsRATE_LIMITED (429): 30 a minute per IP, plus the per-account login limit
Two-factor authentication enabledThe player continues in the login page’s two-factor step and enters their code

The Telegram profile stored for the account (username, name, photo, language, premium status) is refreshed on each sign-in.

Telegram passes the launch data in the page URL (#tgWebAppData=...), so the data alone does not prove that Telegram opened the page: someone can send a link that carries their own, validly signed launch data. Signing in with it would put the visitor in that person’s account.

The plugin therefore only signs in without asking when a real Telegram client hosts the page:

  • the Telegram apps for iOS, Android and desktop, which provide their native Mini App bridge (window.TelegramWebviewProxy), or
  • Telegram Web, which shows the Mini App in a frame and answers the plugin’s web_app_request_theme request from https://web.telegram.org (see Telegram’s Mini App events). Your site sends X-Frame-Options: SAMEORIGIN by default, so Telegram Web can only show the Mini App if you allow it to frame the site.

Anywhere else the Mini App page and the login button name the Telegram account the data belongs to and sign in only after the player clicks: "Continue as @username", or, for an account without a Telegram username, its name in quotes with its numeric ID (Continue as "Alice B" (Telegram ID 12345)), because a name is whatever the sender typed and could look like someone else’s username. Outside a Telegram client the sign-in is also sign-in only: it works for a Telegram account that a player already has, and creates no account and offers no link for any other (the player sees "No player has this Telegram account yet"). Settings → Telegram offers Link Telegram and Set a password only inside a Telegram client.

Auto-Provisioned Accounts

When Allow Auto-Provisioning is on, the first sign-in from an unknown Telegram identity creates an account:

  • Username: the sanitized Telegram username if it is available, otherwise the prefix plus six random digits.
  • Email: tg_<telegram-id>@telegram.invalid, marked as confirmed and never mailed.
  • Password: none the player knows, until they set their own.
  • Group, approval, referral: as for any registration. A startapp parameter in the Mini App link is used as the referral code.

Linking, Unlinking and Passwords

Players manage Telegram in Settings:

  • Sign-in methods lists the Telegram link and unlinks it. Unlinking is refused while Telegram is the account’s only way to sign in.
  • Telegram (inside the Mini App only) has Link Telegram for an account signed in another way, and Set a password for an account that has none. Link Telegram first asks "Link Telegram account @name to your player?", and it needs a sign-in of the last 10 minutes; after that the player is asked to sign in again (REAUTH_REQUIRED). Both rules apply to every provider that signs in with a credential.

Setting a Password

A Telegram-only player opens Settings inside the Mini App and clicks Set a password in the Telegram section. Telegram confirms it is them (the Mini App’s own launch data, accepted again within InitData Max Age), then the Sign-in methods password form opens. After saving, they can sign in with their username and that password too. If the Mini App has been open longer than InitData Max Age, reopening it fixes the confirmation.

Password reset emails still don’t work for these accounts, because they would go to the undeliverable telegram.invalid address. An admin can also set the password from the user’s record.

Admin

  • Players › Linked Accounts: every Telegram link (filter by provider Telegram), with an audited Unlink that revokes the player’s sessions.
  • The Sign-in methods panel of the user drawer: one player’s links.
  • Settings › Login Providers: Telegram’s status, owning plugin, number of linked players and the sign-up mode override.

API

The plugin has no routes of its own. The Mini App and the login button post to the engine:

MethodPathPermissionDescription
POST/api/v1/auth/external/telegram/credentialPublic (login); session + CSRF (link, reauth){ "credential": { "initData": "..." }, "intent": "login" | "link" | "reauth", "mode": "cookie" | "token" }
GET/api/v1/user/identitiesAuthenticatedThe player’s sign-in methods
DELETE/api/v1/user/identities/telegramAuthenticated + CSRFUnlink
POST/api/v1/user/identities/passwordAuthenticated + CSRF{ reauthTicket, newPassword } after a reauth

The answer has a status (signed_in, requires_2fa with a tempToken, linked, reauth_ok with a ticket, …). See Login Providers.

More about Telegram Auth

Try the live demo Pricing

Have questions about Poker Engine? We reply fast.