PHP code example of azate / laravel-telegram-login-auth
1. Go to this page and download the library: Download azate/laravel-telegram-login-auth library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
azate / laravel-telegram-login-auth example snippets
// app/Http/Controllers/AuthController.php
namespace App\Http\Controllers;
// ...
use Azate\LaravelTelegramLoginAuth\TelegramLoginAuth;
use Illuminate\Http\Request;
// ...
public function handleTelegramCallback(TelegramLoginAuth $telegramLoginAuth, Request $request)
{
if ($user = $telegramLoginAuth->validate($request)) {
// ...
}
// ...
}
// app/Http/Controllers/AuthController.php
namespace App\Http\Controllers;
// ...
use Azate\LaravelTelegramLoginAuth\Contracts\Telegram\NotAllRequiredAttributesException;
use Azate\LaravelTelegramLoginAuth\Contracts\Validation\Rules\ResponseOutdatedException;
use Azate\LaravelTelegramLoginAuth\Contracts\Validation\Rules\SignatureException;
use Azate\LaravelTelegramLoginAuth\TelegramLoginAuth;
use Illuminate\Http\Request;
// ...
public function handleTelegramCallback(TelegramLoginAuth $telegramLoginAuth, Request $request)
{
try {
$user = $telegramLoginAuth->validateWithError($request);
} catch(NotAllRequiredAttributesException $e) {
// ...
} catch(SignatureException $e) {
// ...
} catch(ResponseOutdatedException $e) {
// ...
} catch(Exception $e) {
// ...
}
// ...
}