I'm trying to write an SSO implementation and for that I need to override some methods such as Auth::check()
which are implemented in the Guard
class.
I don't understand, however, how to extend that class using service providers. I tried looking in the AuthServiceProvider
but there is a whole lot of mumbo jumbo going on I don't understand.
I figured it out! Fairly simple:
<?php
namespace Animekyun\Providers;
use Animekyun\Auth\CustomGuard;
use Illuminate\Auth\EloquentUserProvider;
use Illuminate\Support\ServiceProvider;
class SsoServiceProvider extends ServiceProvider
{
public function boot()
{
\Auth::extend('custom', function () {
return new CustomGuard(
new EloquentUserProvider(
$this->app['hash'],
$this->app['config']['auth.model']),
$this->app['session.store']);
});
}
public function register()
{
}
}
and the CustomGuard
class:
<?php
namespace Animekyun\Auth;
use Illuminate\Auth\Guard;
class CustomGuard extends Guard
{
public function check() {
// do some stuff
return parent::check();
}
}