Telegram
An error occurred:
PUBLIC_KEY_INVALID
Apart from the correct data from @jwilliamson45
Please note how to place the public_key
. Here is an example that works for tests,
Since the documentation of python-telegram-bot
doesn't explain this in detail, it just mentions it (until today, December 7, 2024):
<?php
$tg_passport = empty($_GET["tg_passport"])? "":$_GET["tg_passport"];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title> Telegram passport (test1) </title>
<meta charset="utf-8">
<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta content="width=device-width, initial-scale=1" name="viewport">
</head>
<body>
<h1>Telegram passport (test1)</h1>
<?php
if ($tg_passport == "cancel") {
echo "Canceled!";
}
?>
<div id="telegram_passport_auth"></div>
</body>
<!--- Needs file from https://github.com/TelegramMessenger/TGPassportJsSDK downloaded --->
<script src="../telegram-passport.js"></script>
<script src="../uuid.min.js"></script>
<script>
"use strict";
var host = "https://your-host.net"
var nonce = uuid.v4(), callback_url = host+"/apps/telegram_passport_auth",
files_base_url = callback_url+"/files",
files_dir = callback_url+"/files_saved";
// Example of public key
var p_k="-----BEGIN PUBLIC KEY-----\n"+
"MIIBIjANBC\n"+
"mPPAR7busb\n"+
"TmxT4yQswX\n"+
"2TLg46ccdi\n"+
"Tbam9PQiw4\n"+
"Sb7Tqii9xl\n"+
"QQIAB\n"+
"-----END PUBLIC KEY-----\n";
Telegram.Passport.createAuthButton('telegram_passport_auth', {
// ROLL BOT:
bot_id: 999999999,
// WHAT DATA YOU WANT TO RECEIVE:
scope: {
data: [{
type: 'id_document',
selfie: true
}, 'address_document', 'phone_number', 'email'],
v: 1
},
// YOUR PUBLIC KEY
public_key: p_k,
// YOUR BOT WILL RECEIVE THIS DATA WITH THE REQUEST
nonce: nonce,
// TELEGRAM WILL SEND YOUR USER BACK TO THIS URL
callback_url: callback_url+"/?"
});
</script>
</html>
The nonce
is generated with uuid.v4() from uuid.min.js.
Maybe this detail influences or not in the error: PUBLIC_KEY_REQUIRED