azate / laravel-telegram-login-auth
Laravel Telegram 登录认证
v2.4.0
2024-03-20 20:01 UTC
Requires
- php: ^8
- illuminate/config: ^9 || ^10 || ^11
- illuminate/contracts: ^9 || ^10 || ^11
- illuminate/http: ^9 || ^10 || ^11
- illuminate/support: ^9 || ^10 || ^11
README
本包是一个 Laravel 服务提供者,它支持 Laravel 登录,并且非常容易与任何需要Telegram身份验证的项目集成。
安装
使用 composer 安装此包。
composer require azate/laravel-telegram-login-auth
Laravel >=5.5 使用包自动发现,因此不需要您手动添加 ServiceProvider。
使用发布命令将包配置复制到您的本地配置
php artisan vendor:publish --provider="Azate\LaravelTelegramLoginAuth\Providers\LaravelServiceProvider" --tag=config
使用示例
设置信息 Telegram 登录小部件
错误信息不详细
// 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) { // ... } // ... }