我正在尝试编写SSO实现,为此我需要覆盖Auth::check()
类中实现的Guard
等方法。
但是,我不了解如何使用服务提供商扩展该类。我试着查看AuthServiceProvider
,但是有很多关于我不明白的傻瓜大肆宣传。
答案 0 :(得分:0)
我明白了!相当简单:
<?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()
{
}
}
和CustomGuard
类:
<?php
namespace Animekyun\Auth;
use Illuminate\Auth\Guard;
class CustomGuard extends Guard
{
public function check() {
// do some stuff
return parent::check();
}
}