Telegram’s older Login Widget sends signed profile fields; Telegram’s current “Log In With Telegram” documentation describes a JavaScript library and OpenID Connect (OIDC), and marks the iframe-based widget documentation as archived. Pick the flow your integration actually uses: legacy widget fields are verified with an HMAC derived from the bot token, while OIDC uses an ID-token signature and claim checks. These methods are not interchangeable.
Choose the Telegram login flow before writing the callback
The legacy widget and current login flow have different payloads and verification rules. Telegram’s legacy Login Widget documentation says, “The Telegram login widget is a simple way to authorize users on your website.” Its iframe-based documentation is now archived; Telegram’s current Log In With Telegram page documents a JavaScript library and standard OIDC as an alternative.
| Decision point | Legacy Login Widget | Current Log In With Telegram / OIDC |
|---|---|---|
| What reaches your application | Signed profile fields, delivered by redirect or JavaScript callback. | OIDC authorization response and, after code exchange, an ID token. |
| Server-side verification | HMAC-SHA-256 of canonicalized fields, using a secret derived from the bot token. | Validate the ID-token signature and claims, including issuer, audience and expiration. |
| Browser and callback pattern | Redirect to the configured URL or call the configured JavaScript callback. | Authorization Code with PKCE; the documented JavaScript popup flow also involves cross-origin popup communication. |
| Configuration | Link the website domain to the bot with BotFather’s /setdomain command. |
Register Allowed URLs in BotFather, including the appropriate origins or redirect URLs for the integration. |
| Existing OIDC infrastructure | Requires handling Telegram’s signed field payload; it is not an OIDC ID token. | Can fit an application’s OIDC architecture, provided it correctly implements Telegram’s authorization and token-validation requirements. |
Do not infer that either flow is universally more secure: security depends on the application’s integration and threat model. If your product requirements allow a new integration, evaluate Telegram’s current OIDC documentation rather than treating archived iframe-widget instructions as current. No Yii2-specific package or compatibility claim is established here.
Prepare the legacy widget and protect its callback
Configure the bot and domain
A bot is required for the widget. Telegram directs site owners to use BotFather’s /setdomain command to link the website domain to that bot. Keep the bot token on the server: never put it in a template, JavaScript bundle or other browser-delivered code. If the token is disclosed, rotate it through BotFather.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Receive either delivery form as untrusted input
The legacy widget can redirect the user to a configured URL with authentication fields, or invoke a configured JavaScript callback with those fields. In Yii2, a practical architecture is a server-side controller action that receives the callback and passes the received fields to a small validation service. A browser redirect or callback firing proves only that the browser delivered data; it does not authenticate the person.
Check the exact expected field set for the widget integration you configured. Reject missing or malformed required values, and reject the request unless the signature check succeeds. Only then look up or create the local account and establish the Yii2 application session.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Verify legacy Login Widget fields in PHP
Telegram’s legacy check is based on every received data field except hash. Sort fields by key, format each as key=value, join the lines with a single line-feed character, derive the HMAC key by taking SHA-256 of the bot token, and calculate an HMAC-SHA-256 over the resulting data-check string. Compare the resulting lowercase hexadecimal digest with the received hash.
The following PHP example illustrates the legacy recipe. Adapt the required-field list to the exact widget payload your application accepts, and run validation on the server. It assumes the PHP runtime provides hash_equals.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
<?php
function verifyTelegramLoginWidget(array $input, string $botToken, int $maxAgeSeconds): array
{
if ($botToken === '' || $maxAgeSeconds < 1) {
throw new InvalidArgumentException('Invalid Telegram login configuration.');
}
// This example expects the standard legacy widget identity fields.
$required = ['id', 'auth_date', 'hash'];
foreach ($required as $key) {
if (!isset($input[$key]) || !is_string($input[$key]) || $input[$key] === '') {
throw new InvalidArgumentException('Missing or malformed Telegram field.');
}
}
$receivedHash = $input['hash'];
if (!preg_match('/A[a-f0-9]{64}z/i', $receivedHash)) {
throw new InvalidArgumentException('Malformed Telegram hash.');
}
$fields = $input;
unset($fields['hash']);
foreach ($fields as $key => $value) {
if (!is_string($key) || !is_scalar($value)) {
throw new InvalidArgumentException('Malformed Telegram field.');
}
$fields[$key] = (string) $value;
}
ksort($fields, SORT_STRING);
$lines = [];
foreach ($fields as $key => $value) {
$lines[] = $key . '=' . $value;
}
$dataCheckString = implode("n", $lines);
$secretKey = hash('sha256', $botToken, true);
$expectedHash = hash_hmac('sha256', $dataCheckString, $secretKey);
if (!hash_equals(strtolower($expectedHash), strtolower($receivedHash))) {
throw new RuntimeException('Telegram signature verification failed.');
}
if (!ctype_digit($input['auth_date'])) {
throw new InvalidArgumentException('Malformed Telegram authentication time.');
}
$authDate = (int) $input['auth_date'];
$now = time();
if ($authDate > $now || ($now - $authDate) > $maxAgeSeconds) {
throw new RuntimeException('Telegram login data is stale or from the future.');
}
return $fields;
}
Pass the token from server-side configuration or a secret manager, not from a request or client-side setting. The function uses the raw 32-byte SHA-256 digest as the HMAC key (true in PHP’s hash call); omitting that parameter would produce hexadecimal text instead and would not match Telegram’s recipe. The canonical string has no URL encoding, extra whitespace or trailing newline. Do not discard received fields before building it: verify all fields in the received payload except hash.
Choose an explicit freshness window
Signature validity and freshness are separate checks. Telegram defines auth_date as the Unix timestamp at which authentication was received and says it can be checked to prevent outdated data, but does not prescribe a maximum age. Choose a maximum age that fits your sign-in flow and document it as application policy; the example requires the caller to supply that value. Reject future timestamps as well as expired ones to avoid accepting implausible values.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Connect successful verification to a Yii2 account
Keep Telegram validation separate from account and session handling. A controller can receive the request, call the validation service, and only on success use the verified Telegram user ID to resolve the local identity. A simplified flow is:
- Receive the redirect request or callback fields in a server-side Yii2 controller action.
- Validate field types and required values, verify the signature, and enforce the application’s freshness policy.
- Find the local account by the verified Telegram user ID, stored as an external identity key; if account creation is allowed, create or link the account according to your site’s account-linking policy.
- Establish the Yii2 application session only after the identity has been validated and resolved.
Use Telegram’s user id as the external identity key. Names, usernames and profile fields can change, so they should not serve as the durable account key. Do not allow a matching display name or a client-side event to bypass server-side signature verification.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteBest Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Implement Telegram’s current OIDC flow separately
OIDC is not a variant of the legacy hash check. Telegram documents Authorization Code with PKCE, recommends the S256 PKCE method, and requires Allowed URLs to be configured through BotFather. Generate and retain a per-login state value, check it on the callback to protect against CSRF, and exchange the authorization code on the server. Then validate the ID-token signature and claims rather than treating a decoded token as trustworthy.
- Check the ID token’s issuer against
https://oauth.telegram.org. - Check that its audience matches the bot Client ID.
- Check that
exphas not passed, along with the other applicable token-validation requirements. - Keep the code exchange and client credentials on the server, and do not use the legacy bot-token-derived HMAC recipe to validate the ID token.
Telegram warns that popup communication from telegram-login.js fails when the page uses Cross-Origin-Opener-Policy: same-origin. Its page suggests removing that header or using same-origin-allow-popups. Treat this as a compatibility decision for pages using that popup flow, not as a reason to weaken security headers site-wide without assessing the consequences.
Quick Recap
Common implementation failures to avoid
- Using the wrong verifier: legacy widget fields need the bot-token-derived HMAC procedure; OIDC requires ID-token signature and claim validation.
- Canonicalizing different data: encoding values, changing whitespace, omitting received fields or adding a trailing newline changes the legacy data-check string.
- Checking only the hash: a valid signature does not make old authentication data fresh; apply an explicit
auth_dateage limit. - Trusting browser-side behavior: callback execution, redirect arrival or visible profile details are not proof until the server verifies the payload.
- Exposing credentials: bot tokens belong in server-side secrets, never templates, browser code or logs.
- Assuming a Yii2 extension is compatible: no Yii2-specific integration or maintained package is established by Telegram’s cited documentation. Before adopting a library, verify its maintenance status, supported PHP and Yii2 versions, token-validation behavior and alignment with the flow Telegram currently documents.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

