tma-spring-security provides backend security support for Telegram Mini Apps in Java/Spring applications.
The library validates raw Telegram Mini App initData using the bot token and exposes a verified context for request handling.
As a Spring Boot backend developer, I want to add one dependency and configure my Telegram bot token, so that requests from my Telegram Mini App are validated automatically and my controllers can access the verified Telegram user.
- Parse raw
initDataquery string. - Validate required
hashfield. - Calculate Telegram Mini App data-check-string.
- Validate HMAC-SHA256 signature using the bot token.
- Parse
auth_date. - Reject expired initData when
maxAuthAgeis configured. - Parse
user,chat,query_id, andstart_paramwhere present.
- Auto-configure validator from properties.
- Read raw initData from configurable HTTP header.
- Validate each request when the header is present.
- Store validated context in a request-bound holder.
- Clear context after request completion.
- Support
@TelegramMiniAppUsercontroller argument. - Support
@TelegramMiniAppcontroller argument.
- Provide a
TelegramMiniAppAuthenticationToken. - Provide a
TelegramMiniAppPrincipal.
telegram:
miniapp:
enabled: true
bot-token: ${TELEGRAM_BOT_TOKEN}
header-name: X-Telegram-Init-Data
max-auth-age: 1h
fail-on-missing-header: false