invisnik/laravel-steam-auth


Laravel Steam Auth

License: MIT

Language: PHP

Keywords: laravel-steam, php, steam-api, steam-authentication


Steam authentication for Laravel

Code Climate Latest Stable Version Total Downloads License

This package is a Laravel 5 service provider which provides support for Steam OpenID and is very easy to integrate with any project that requires Steam authentication.

Requirements

  • PHP 7.1+
  • Laravel 5.8+

Installation

Via Composer

composer require invisnik/laravel-steam-auth

Steam API Key

Add your Steam API key to your .env file. You can get your API key here.

STEAM_API_KEY=SomeKindOfAPIKey

Config Files

Publish the config file.

php artisan vendor:publish --provider="Invisnik\LaravelSteamAuth\SteamServiceProvider"

Usage example

In config/steam-auth.php:

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,
];

In routes/web.php:

Route::get('auth/steam', 'AuthController@redirectToSteam')->name('auth.steam');
Route::get('auth/steam/handle', 'AuthController@handle')->name('auth.steam.handle');

Note: if you want to keep using Laravel's default logout route, add the following as well:

Route::post('logout', 'Auth\LoginController@logout')->name('logout');

In AuthController:

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
        ]);
    }
}

Should you wish to use a login redirection URL that is differant from the one you specified in the config

// Inside your controller login method
$this->steam->setRedirectUrl(route('login.route'));

...

return $this->steam->redirect();

If you need another steamID you can use another package to convert the given steamID64 to another type like xPaw/SteamID.

Project Statistics

Sourcerank 8
Repository Size 103 KB
Stars 139
Forks 49
Watchers 11
Open issues 4
Dependencies 6
Contributors 18
Tags 31
Created
Last updated
Last pushed

Top Contributors See all

Nikita Brytkov Tom Witkowski Alex Toff Chris Konnertz Joel timetorock Jérémy Barbe Luuk Holleman Mahmoud Zalt Tom Grand Silence Maras Chen Christian Maioli (@amazedcoder) Oyebanji Jacob Mayowa João Dias metroyanno nikkiii Ron Melkhior

Packages Referencing this Repo

invisnik/laravel-steam-auth
Laravel Steam Auth
Latest release v4.1.0 - Updated - 139 stars

Recent Tags See all

v4.1.0 September 10, 2019
v4.0.0 April 25, 2019
v3.5.0 March 28, 2019
v3.4.0 February 06, 2019
v3.3.0 April 13, 2018
v3.2.1 April 06, 2018
v3.2.0 February 27, 2018
v3.1.2 September 01, 2017
v3.1.1 August 27, 2017
v3.1.0 August 13, 2017
v3.0.0 August 10, 2017
v2.3.5 May 16, 2017
v2.3.4 May 09, 2017
v2.3.3 March 25, 2017
v2.3.2 January 25, 2017

Interesting Forks See all

DavisMiculis/lumen-steam-auth
Laravel Lumen Steam Auth
PHP - Last pushed - 2 stars
kanazaca/laravel-steam-auth
Laravel Steam Auth
PHP - MIT - Last pushed - 2 stars
slowerua/laravel-steam-auth
Laravel Steam Auth
PHP - Updated - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2019-11-14 04:38:07 UTC

Login to resync this repository