PHP code example of eliuflorez / steam-auth

1. Go to this page and download the library: Download eliuflorez/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/ */

    

eliuflorez / steam-auth example snippets


'providers' => [
	// ...
	EliuFlorez\SteamAuth\SteamServiceProvider::class,
]

return [

    /*
     * Redirect URL after login
     */
    'redirect_url' => '/login',
	
    /*
     *  API Key (http://steamcommunity.com/dev/apikey)
     */
    'api_key' => 'Your API Key'

];


get('login', 'AuthController@login');

namespace App\Http\Controllers;

use EliuFlorez\SteamAuth\SteamAuth;
use App\User;
use Auth;

class AuthController extends Controller
{

    /**
     * @var SteamAuth
     */
    private $steam;

    public function __construct(SteamAuth $steam)
    {
        $this->steam = $steam;
    }

    public function login()
    {
        if ($this->steam->validate()) { 
            $info = $this->steam->getUserInfo();
            if (! is_null($info)) {
                $user = User::where('steamid', $info->getSteamID64())->first();
                if (!is_null($user)) {
                    Auth::login($user, true);
                    return redirect('/'); // redirect to site
                }else{
                    $user = User::create([
                        'username' => $info->getNick(),
                        'avatar'   => $info->getProfilePictureFull(),
                        'steamid'  => $info->getSteamID64()
                    ]);
                    Auth::login($user, true);
                    return redirect('/'); // redirect to site
                }
            }
        } else {
            return $this->steam->redirect(); // redirect to Steam login page
        }
    }
}


php artisan vendor:publish