Download the PHP package tg/tgwebvalid without Composer
On this page you can find all versions of the php package tg/tgwebvalid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tg/tgwebvalid
More information about tg/tgwebvalid
Files in tg/tgwebvalid
Package tgwebvalid
Short Description An easy way to validate Telegram Login Widget and Telegram Mini App users on your website using PHP
License MIT
Homepage https://tgwebvalid.com/en/
Informations about the package tgwebvalid
Library for Telegram Web App User Validation and Telegram Login Widget for PHP
About TgWebValid
They say we are cool 😎
⭐️ Support us, give us a star on GitHub and become our sponsor 😊
🙏 Please let us know on GitHub if something isn't working for you or if you need additional functionality
User authentication occurs by encrypting the received, raw, user data and comparing it with the hash provided by the telegram. A failed check can be equated with a possible attempt to bypass or hack the system.
The library verifies users Telegram Login Widget and Telegram Web App
WARNING
: Use user data only after successful authentication
To quickly and safely verify a user, we recommend following a few simple steps
Installation
You can install the TgWebValid library through the composer package manager by executing the command
Add the --no-dev
flag to install only the dependencies needed to run your project in a production environment.
Using
The first thing you need to do is to set in the constructor of the TgWebValid class the token of the Telegram bot on behalf of which authentication is performed by default. And store the result in a variable.
Also, if you want to throw an exception in case of a validation error, set the second parameter to true. But be sure to use the try catch
structure
If your project uses multiple bots, you can easily interact with them, just add them all
Getting a bot to work is easy. Specify the name of the bot to work with, or leave the argument empty to get the default bot
Next, you need to decide on the type of authentication you need to do.
- Web App Authentication Example
- Login Widget Authentication Example
Telegram Web App authentication
To perform this type of verification, you should use the validateInitData
method. Which argument accepts data for processing. If the validation is successful, you will be returned an InitData
object with the data, or false
if the validation fails.
Use the second argument to enable or disable an exception on failed validation
Note
. Certain data is present depending on the situation, so sometimes it can be null
instead of data or a data object. More details in the Telegram official documentation
Telegram Login Widget authentication
To perform this type of check, you should use the validateLoginWidget
method. Which argument accepts an array with raw user data. You will be returned a LoginWidget
object with the data, or false
if the validation fails
Use the second argument to enable or disable an exception on failed validation
Note
. Certain data is present depending on the situation, so sometimes it can be null
instead of data or a data object.
Full example
Additionally
Our library is autonomous, so it can be used in any frameworks, or without them.
Security
If you discover a security vulnerability in TgWebValid, please create an issue with a detailed description. All security vulnerabilities will be fixed immediately. Pull requests are also welcome.
Assistance
We will be glad if you join the development and improvement of the project. You can create an issue and/or a pull request
License
TgWebValid - is open source software available under the license file for more information.