Laravel 5.2 SessionGuard Extension

I want to extend Laravel stock authentication to use the OAuth server to search and authenticate users, taking advantage of existing functionality. I have already managed to expand EloquentUserProviderto partially rewrite / expand the implementation of the contract Illuminate\Contracts\Auth\UserProvider. The current implementation is as follows:

class EloquentOauthServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return HcOAuthProvider;
     */
    public function boot()
    {
        Auth::provider('oauth',function($app){
            $model = $app['config']['auth.providers.oauth.model'];
            $repository = new OauthUserRepository();
            return new EloquentOauthUserProvider($app['hash'], $model, $repository);
        });
    }

}

In the configuration, auth.phpI changed the descriptors as follows:

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'oauth',
    ],
]

'providers' => [
    'oauth' => [
        'driver' => 'oauth',
        'model' => App\Models\User::class,
    ],
]

, . , SessionGuard (login logout, ), OAuth, Laravel. , (, Laravel 5.2), Authmanager, overkill.

, : Laravel 5.2 SessionGuard?

+4
1

, , , .

<?php
namespace App\CoreExtensions;
use Illuminate\Auth\SessionGuard;
use Illuminate\Contracts\Auth\Authenticatable;
class SessionGuardExtended extends SessionGuard
{
    /**
     * Log a user into the application.
     *
     * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
     * @param  bool  $remember
     * @return void
     */
    public function login(Authenticatable $user, $remember = false)
    {
        $this->updateSession($user->getAuthIdentifier());
        if ($remember) {
            $this->refreshRememberToken($user);
            $this->queueRecallerCookie($user);
        }
        $this->fireLoginEvent($user, $remember);
        $this->setUser($user);
    }
}

AppServiceProvider.php

public function boot()
{
    Auth::extend(
        'sessionExtended',
        function ($app) {
            $provider = new EloquentUserProvider($app['hash'], config('auth.providers.users.model'));
            return new SessionGuardExtended('sessionExtended', $provider, app()->make('session.store'), request());
        }
    );
}

Config/auth.php

'web' => [
    'driver' => 'sessionExtended',
    'provider' => 'users',
],
+3

All Articles