WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

cnncodex/TMA-Auth-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

TMA-Auth-Backend

Telegram Mini App Authenticate with intidata | Flask backend

โ˜˜๏ธ Frontend examples

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

profile