initData in Eight Steps: A Recipe Card
Cheat sheets · 2026-11-06 · 18+ readers
When a Mini App sends you initData, treat it as a claim until you verify it. This is the recipe, in order.
Ingredients
- The raw
initDatastring from the browser. - Your bot token, on the server only.
Steps
- Split the string into key and value pairs, decoding the values.
- Take out
hashand keep it. - Sort the other pairs by key.
- Join them as
key=value, one per line. - Make a secret: HMAC-SHA256 with the key
WebAppDataand your token as the message. - HMAC-SHA256 the joined text with that secret and write the result in hex.
- Compare with
hashusing a constant time check. - Make sure
auth_dateis recent.
Mix-ups to avoid
| Mistake | Effect |
|---|---|
| Swapping key and message in step 5 | Every check fails |
| Using the encoded text | Hash never matches |
Leaving hash in | Hash never matches |
| Skipping step 8 | Old 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.