azate / laravel-wargaming-auth
此包已被废弃,不再维护。没有建议的替代包。
Laravel Wargaming Auth
v2.1.0
2018-09-14 13:59 UTC
Requires
- php: ^7.0
- guzzlehttp/guzzle: ^6.2
- illuminate/http: 5.5.x|5.6.x|5.7.x
- illuminate/routing: 5.5.x|5.6.x|5.7.x
- illuminate/support: 5.5.x|5.6.x|5.7.x
README
此包是一个Laravel 5服务提供者,它提供了对Wargaming OpenID的支持,并且与任何需要Wargaming身份验证的项目集成非常简单。
安装
使用Composer安装此包。
composer require azate/laravel-wargaming-auth
Laravel >=5.5使用包自动发现,因此不需要您手动添加ServiceProvider。
使用发布命令将包配置复制到您的本地配置
php artisan vendor:publish --provider="Azate\Laravel\WargamingAuth\Providers\WargamingAuthServiceProvider"
使用示例
在routes/web.php中
Route::get('auth/wargaming/{wargamingAuthRegion?}', 'AuthController@redirectToWargaming')->name('auth.wargaming'); Route::get('auth/wargaming/callback', 'AuthController@handleWargamingCallback')->name('auth.wargaming.handle');
在AuthController中
namespace App\Http\Controllers; use Azate\Laravel\WargamingAuth\WargamingAuth; use Illuminate\Http\RedirectResponse; class AuthController extends Controller { /** * @var WargamingAuth */ protected $wargamingAuth; /** * AuthController constructor. * * @param WargamingAuth $wargamingAuth */ public function __construct(WargamingAuth $wargamingAuth) { $this->wargamingAuth = $wargamingAuth; } /** * Redirect the user to the authentication page. * * @param string|null $region * * @return RedirectResponse */ public function redirectToWargaming(string $region = null): RedirectResponse { if ($region) { $this->wargamingAuth->setRegion($region); } return new RedirectResponse($this->wargamingAuth->redirectUrl()); } /** * Get user info and log in (hypothetically). * * @return RedirectResponse */ public function handleWargamingCallback(): RedirectResponse { if ($this->wargamingAuth->verify()) { $user = $this->wargamingAuth->user(); // return new RedirectResponse('/'); } return $this->redirectToWargaming(); } }