PHP code example of azate / laravel-wargaming-auth
1. Go to this page and download the library: Download azate/laravel-wargaming-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/ */
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();
}
}