TSocial TSocial
Open in Telegram
Better in TelegramOpen in Telegram
TSocial planet logoTelesocial

Telesocial › Cheat sheets

initData in Eight Steps: A Recipe Card

Cheat sheets · 2026-11-06 · 18+ readers

When a Mini App icon (grid) Mini App sends you initData, treat it as a claim until you verify it. This is the recipe, in order.

Ingredients

  • The raw initData string from the browser.
  • Your bot icon bot token, on the server only.

Steps

  1. Split the string into key and value pairs, decoding the values.
  2. Take out hash and keep it.
  3. Sort the other pairs by key.
  4. Join them as key=value, one per line.
  5. Make a secret: HMAC-SHA256 with the key WebAppData and your token as the message.
  6. HMAC-SHA256 the joined text with that secret and write the result in hex.
  7. Compare with hash using a constant time check.
  8. Make sure auth_date is recent.

Mix-ups to avoid

MistakeEffect
Swapping key and message in step 5Every check fails
Using the encoded textHash never matches
Leaving hash inHash never matches
Skipping step 8Old strings stay valid

After it passes

Look up the user by user.id, then issue your own session. Do not keep re-trusting the browser.

Frequently asked questions

Is this the same as the Login Widget?

No. The widget uses a different secret.

Can I check without the token?

Telegram offers an Ed25519 signature for third party checks. Read the docs for the exact string to sign.

How old can auth_date be?

Choose a limit that fits your sessions, such as an hour.

More cheat sheets

initData in Eight Steps: A Recipe Card | Telesocial