Использую
https://github.com/invisnik/laravel-steam-auth
почему-то авторизация проходит через раз, а если проходит то может сброситься при переходе на какую-нибудь ссылку которая доступна только зарегистрированному пользователю
AuthController
namespace App\Http\Controllers;
use Invisnik\LaravelSteamAuth\SteamAuth;
use App\User;
use Illuminate\Support\Facades\Auth;
class AuthController extends Controller
{
protected $steam;
protected $redirectURL = '/';
public function __construct(SteamAuth $steam)
{
$this->steam = $steam;
}
public function redirectToSteam()
{
return $this->steam->redirect();
}
public function handle()
{
if ($this->steam->validate()) {
$info = $this->steam->getUserInfo();
if (!is_null($info)) {
$user = $this->findOrNewUser($info);
Auth::login($user, true);
return redirect($this->redirectURL); // redirect to site
}
}
return $this->redirectToSteam();
}
protected function findOrNewUser($info)
{
$user = User::where('steamid', $info->steamID64)->first();
if (!is_null($user)) {
return $user;
}
return User::create([
'username' => $info->personaname,
'avatar' => $info->avatarfull,
'steamid' => $info->steamID64
]);
}
}
web.php
Route::get('auth/steam/handle', 'AuthController@handle')->name('auth.steam.handle');
Route::get('auth/steam', 'AuthController@redirectToSteam')->name('auth.steam');
Route::get('/', 'PagesController@index')->name('index');
Route::group(['middleware' => ['auth']], function () {
Route::get('/profile', ['as' => 'changes', 'uses' =>'PagesController@profile']);
});
PagesController.php class PagesController extends Controller
{
public function index()
{
if(!Auth::check()){
return view('enter');
} else {
return view('index');
}
}
public function profile()
{
return view('profile');
}
}
steam-auth.phpreturn [
'redirect_url' => '/auth/steam/handle',
//'realm' => 'redirected.com',
'api_key' => env('STEAM_API_KEY', ''),
'https' => false,
];