1. Go to this page and download the library: Download invisnik/laravel-steam-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/ */
invisnik / laravel-steam-auth example snippets
return [
/*
* Redirect URL after login
*/
'redirect_url' => '/auth/steam/handle',
/*
* Realm override. Bypass domain ban by Valve.
* Use alternative domain with redirection to main for authentication (banned by valve).
*/
// 'realm' => 'redirected.com',
/*
* API Key (set in .env file) [http://steamcommunity.com/dev/apikey]
*/
'api_key' => env('STEAM_API_KEY', ''),
/*
* Is using https?
*/
'https' => false,
];
namespace App\Http\Controllers;
use Invisnik\LaravelSteamAuth\SteamAuth;
use App\User;
use Auth;
class AuthController extends Controller
{
/**
* The SteamAuth instance.
*
* @var SteamAuth
*/
protected $steam;
/**
* The redirect URL.
*
* @var string
*/
protected $redirectURL = '/';
/**
* AuthController constructor.
*
* @param SteamAuth $steam
*/
public function __construct(SteamAuth $steam)
{
$this->steam = $steam;
}
/**
* Redirect the user to the authentication page
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function redirectToSteam()
{
return $this->steam->redirect();
}
/**
* Get user info and log in
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
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();
}
/**
* Getting user by info or created if not exists
*
* @param $info
* @return User
*/
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
]);
}
}
// Inside your controller login method
$this->steam->setRedirectUrl(route('login.route'));
...
return $this->steam->redirect();