Steam OpenID Authentication on Laravel
Asked Answered
T

2

12

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

Tornado answered 4/3, 2017 at 23:12 Comment(3)
Check out this: github.com/invisnik/laravel-steam-auth > 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. It should do what you want. The ReadMe has detailed instructions on how to set it up.Guideboard
I have been using the steam socialite for a while, never had problemsRichers
What's wrong with using the Steam Socialite package? What dependency issues do you have with it?Immortality
S
2

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
        }
    
Soraya answered 26/7, 2017 at 20:47 Comment(0)
C
0

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.

Commonly answered 27/10, 2017 at 0:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.