user6513042
user6513042

Reputation:

Steam OpenID Authentication on Laravel

On the last weeks, I'm trying to implement a OpenID authentication on my laravel's website, but without success. I can't use laravel/socialite because the package doesn't support steam and think not support OpenID auths too.

Then, I found the community driven project for custom socialite adapters. But the adapters are a mess and uses obsolete dependencies.

A answer will help a lot of people. Help us :c

Upvotes: 12

Views: 3104

Answers (2)

Nisarg Shah
Nisarg Shah

Reputation: 292

Socialite Steam Login

  1. Composer Install

    // This assumes that you have composer installed globally
    composer require socialiteproviders/steam
    
  2. SERVICE PROVIDER

    • Remove Laravel\Socialite\SocialiteServiceProvider from your providers[] array in config\app.php if you have added it already.

    • Add \SocialiteProviders\Manager\ServiceProvider::class to your providers[] array in config\app.php.

      'providers' => [
        // a whole bunch of providers
        // remove 'Laravel\Socialite\SocialiteServiceProvider',
        \SocialiteProviders\Manager\ServiceProvider::class, // add
       ];
      
  3. Add the event and listeners

    protected $listen = [
      \SocialiteProviders\Manager\SocialiteWasCalled::class => [
      // add your listeners (aka providers) here
      'SocialiteProviders\Steam\SteamExtendSocialite@handle',
      ],
    ];
    
  4. ENVIRONMENT VARIABLES in ,env file

    // other values above
    STEAM_KEY=yourapikeyfortheservice
    STEAM_REDIRECT_URI=https://example.com/login
    

sources:- http://socialiteproviders.github.io/providers/steam/

Hopefully, this helps with your steam login.

Upvotes: 0

KorbenDallas
KorbenDallas

Reputation: 1044

You need to use Laravel Steam Auth

Very easy setup:

  1. Composer install

    "invisnik/laravel-steam-auth": "2.*"

  2. Add the service provider to app/config/app.php, within the providers array.

    'providers' => [ Invisnik\LaravelSteamAuth\SteamServiceProvider::class, ]

  3. Publish config: php artisan vendor:publish
  4. Setup your route and API key in config/steam-auth.php
  5. Add route: Route::get('dologin', 'Auth\SteamController@dologin');
  6. Use this live code example, as code from readme not worked for me:

        <?php
    
        public function dologin(Request $request)
        {
            if ($this->steam->validate()) { 
                $info = $this->steam->getUserInfo();
    
                if (! is_null($info)) {
                    $user = User::where('token', $info->get('steamID64'))->first();
                    if (! is_null($user)) {
                        //Update user data, as it change over time..
                        $user->nick = $info->get('personaname');
                        $user->name = $info->get('realname') ?: '';
                        $user->avatar = $info->get('avatarfull');
                        $user->update();
                    } else {
                        $user = User::create([
                            'nick' => $info->get('personaname'),
                            'name' => $info->get('realname') ?: '',
                            'avatar' => $info->get('avatarfull'),
                            'token'  => $info->get('steamID64'),
                        ]);                    
                    }
                    Auth::login($user, true);
                    return redirect('/'); // redirect to site
                }
            } 
            return $this->steam->redirect(); // redirect to Steam login page
        }
    

Upvotes: 2

Related Questions