Refactor configuration and enhance Telegram initData validation
- Improved formatting and readability in config.py and other files by adding line breaks. - Introduced INIT_DATA_MAX_AGE_SECONDS to enforce replay protection for Telegram initData. - Updated validate_init_data function to include max_age_seconds parameter for validation. - Enhanced API to reject old initData based on the new max_age_seconds setting. - Added tests for auth_date expiry and validation of initData in test_telegram_auth.py. - Updated README with details on the new INIT_DATA_MAX_AGE_SECONDS configuration.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""Command handlers: /start, /help; /start registers user and shows Calendar button."""
|
||||
|
||||
import asyncio
|
||||
|
||||
import config
|
||||
@@ -15,7 +16,10 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
user = update.effective_user
|
||||
if not user:
|
||||
return
|
||||
full_name = " ".join(filter(None, [user.first_name or "", user.last_name or ""])).strip() or "User"
|
||||
full_name = (
|
||||
" ".join(filter(None, [user.first_name or "", user.last_name or ""])).strip()
|
||||
or "User"
|
||||
)
|
||||
telegram_user_id = user.id
|
||||
username = user.username
|
||||
first_name = user.first_name
|
||||
@@ -39,9 +43,16 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
|
||||
text = "Привет! Я бот календаря дежурств. Используй /help для списка команд."
|
||||
if config.MINI_APP_BASE_URL:
|
||||
keyboard = InlineKeyboardMarkup([
|
||||
[InlineKeyboardButton("📅 Календарь", web_app=WebAppInfo(url=config.MINI_APP_BASE_URL + "/app/"))],
|
||||
])
|
||||
keyboard = InlineKeyboardMarkup(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
"📅 Календарь",
|
||||
web_app=WebAppInfo(url=config.MINI_APP_BASE_URL + "/app/"),
|
||||
)
|
||||
],
|
||||
]
|
||||
)
|
||||
await update.message.reply_text(text, reply_markup=keyboard)
|
||||
else:
|
||||
await update.message.reply_text(text)
|
||||
|
||||
Reference in New Issue
Block a user