init commit
This commit is contained in:
commit
6570a89f37
2 changed files with 36 additions and 0 deletions
35
index.html
Normal file
35
index.html
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
<!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>
|
||||||
1
readme.txt
Normal file
1
readme.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Пример авторизации через Telegram
|
||||||
Loading…
Add table
Add a link
Reference in a new issue