35 lines
No EOL
1 KiB
HTML
35 lines
No EOL
1 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>OAuth Telegram</title>
|
|
</head>
|
|
<body>
|
|
<h2>OAuth Telegram</h2>
|
|
<input type="text" id="bot-id" placeholder="bot id">
|
|
<button id="telegram-login-button">login</button>
|
|
|
|
<script>
|
|
document.getElementById('telegram-login-button').addEventListener('click', function() {
|
|
const botId = document.getElementById('bot-id').value.trim();
|
|
if (!botId) {
|
|
alert('Please, enter bot id');
|
|
return;
|
|
}
|
|
|
|
const redirectUri = encodeURIComponent(window.location.href);
|
|
|
|
const authUrl = `https://oauth.telegram.org/auth?bot_id=${botId}&origin=${encodeURIComponent(window.location.origin)}&redirect_uri=${redirectUri}&request_access=write`;
|
|
|
|
window.location.href = authUrl;
|
|
});
|
|
|
|
const [, tgAuthResult] = window.location.hash.split('=')
|
|
if (tgAuthResult) {
|
|
const jsonData = JSON.parse(atob(tgAuthResult))
|
|
|
|
document.body.innerHTML = `<h2>User data:</h2><pre>${JSON.stringify(jsonData, null, 2)}</pre>`;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |