https://github.com/cnncodex/tma-auth-backend
Telegram Mini App Authenticate with initdata | Flask backend
https://github.com/cnncodex/tma-auth-backend
api-authentication bearer-token flask flask-web-app init-data python python-flask telegram telegram-bot telegram-data-verification telegram-mini-app telegram-web-app tma tma-auth web-authentication
Last synced: about 1 month ago
JSON representation
Telegram Mini App Authenticate with initdata | Flask backend
- Host: GitHub
- URL: https://github.com/cnncodex/tma-auth-backend
- Owner: cnncodex
- License: mit
- Created: 2024-11-12T16:34:29.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-12-27T17:17:25.000Z (5 months ago)
- Last Synced: 2025-03-27T11:14:00.057Z (about 2 months ago)
- Topics: api-authentication, bearer-token, flask, flask-web-app, init-data, python, python-flask, telegram, telegram-bot, telegram-data-verification, telegram-mini-app, telegram-web-app, tma, tma-auth, web-authentication
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TMA-Auth-Backend
### Telegram Mini App Authenticate with intidata | Flask backend## ☘️ Frontend examples
```javascript
const tg = window.Telegram.WebApp;
tg.ready();
const initData = tg.initData || "";// Check if there is any init data
if (initData) {
// Encode the initdata using Base64 to create an authorization token
const authToken = btoa(initData);// Function to fetch data from an API
async function fetchData() {
try {
const response = await fetch("https://api-endpoint.com", {
method: "GET",
// Set the Authorization header with the Bearer token
headers: {
"Authorization": `Bearer ${authToken}`,
},
});
if (response.ok) {
const data = await response.json();
// console.log("Data fetched successfully:", data);
} else {
console.error("Failed to fetch data:", response.status, response.statusText);
}
} catch (error) {
console.error("Error fetching data:", error);
}
}
fetchData();
} else {
console.log("No initdata available.");
}```
## 🏖 if you have questions | Contact Me
[](https://t.me/cnncodex)