akxz / laravel-telegram-auth
Laravel Telegram 登录认证
dev-master
2020-09-29 06:56 UTC
Requires
- php: >=7.2
- illuminate/http: ~5.6|~5.7|~5.8|^6.0|^7.0|^8.0
- illuminate/support: ~5.6|~5.7|~5.8|^6.0|^7.0|^8.0
- nesbot/carbon: ^1.32|^2.32
This package is not auto-updated.
Last update: 2024-09-26 02:03:49 UTC
README
此包是 Laravel 5-8 的服务提供者,它支持 Laravel 登录,并且很容易与需要 Telegram 认证的任何项目集成。
安装
使用 composer 安装此包。
composer require akxz/laravel-telegram-login-auth
Laravel >=5.5 使用包自动发现,因此不需要您手动添加 ServiceProvider。
使用 publish 命令将包配置复制到您的本地配置
php artisan vendor:publish --provider="Akxz\LaravelTelegramLoginAuth\TelegramLoginServiceProvider"
使用示例
设置信息 Telegram 登录小部件
在 routes/web.php
中:对于 Laravel 5-7
Route::get('auth/telegram/callback', 'AuthController@handleTelegramCallback')->name('auth.telegram.handle');
对于 Laravel 8
use App\Http\Controllers\AuthController; Route::get('auth/telegram/callback', [AuthController::class, 'handleTelegramCallback']);
在 AuthController
中
namespace App\Http\Controllers; use Akxz\LaravelTelegramLoginAuth\TelegramLoginAuth; class AuthController extends Controller { /** * @var TelegramLoginAuth */ protected $telegram; /** * AuthController constructor. * * @param TelegramLoginAuth $telegram */ public function __construct(TelegramLoginAuth $telegram) { $this->telegram = $telegram; } /** * Get user info and log in (hypothetically) * * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse */ public function handleTelegramCallback() { if ($this->telegram->validate()) { $user = $this->telegram->user(); // } return redirect('/'); } }