CrazyTapok-bit / tgWebValid

An easy way to validate Telegram Login Widget and Telegram Mini App users on your website using PHP
https://tgwebvalid.com
MIT License
45 stars 11 forks source link

It doesn't work #58

Closed Lukasss93 closed 1 year ago

Lukasss93 commented 1 year ago

It doesn't work, the data is always invalid.

Steps to reproduce:

  1. I'm using the "Direct Link Web Apps" mode
  2. Frontend side:
    const response = await axios.post('myurl', {
        initData: window.Telegram.WebApp.initData,
    });
  3. Backend side:
    $initData = $_POST['initData'] ?? '';
    $tgWebValid = new TgWebValid('my-bot-token', false);
    $bot = $tgWebValid->bot();
    $validation = $bot->validateInitData($initData);
    if (!$validation) {
        die('Invalid data');
    }

PS: by using the "direct link web app" mode, my initData is: user=%7B%22id%22%3A10081232%2C%22first_name%22%3A%22Luca%22%2C%22last_name%22%3A%22Patera%22%2C%22username%22%3A%22Lukasss93%22%2C%22language_code%22%3A%22it%22%2C%22is_premium%22%3Atrue%2C%22allows_write_to_pm%22%3Atrue%7D&chat_instance=[REDACTED]]&chat_type=private&start_param=foo&auth_date=1693264973&hash=[REDACTED] There is no "query_id" param, maybe it can be this? I hope not.

CrazyTapok-bit commented 1 year ago

Hello. Thank you for the detailed description of your problem. We will analyze the information provided and let you know the result as soon as possible

CrazyTapok-bit commented 1 year ago

@Lukasss93 So, I recreated all the steps you described. After opening our application via the link https://t.me/tgwebvalid_bot/menu and https://t.me/tgwebvalid_bot/menu?startapp=foo (as you did), data validation with the validateInitData method is successful.

Recommendations:

Regarding the query_id, don't worry, it is optional. Sometimes it can really be absent

Please let me know the outcome of the recommendations

Lukasss93 commented 1 year ago

Ops, wrong token, sorry.

CrazyTapok-bit commented 1 year ago

Ops, wrong token, sorry.

It's good that everything worked out. If you need help, please contact