dfoxx/laravel-shibboleth

1.0.0 2017-02-07 23:33 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:01:17 UTC


README

此包为Laravel 5.4和5.5中Shibboleth的认证中间件、自定义守卫和用户提供者提供了一些基本指导。

安装

通过Composer

$ composer require dfoxx/laravel-shibboleth

然后在 config/app.php 中添加服务提供者

Dfoxx\Shibboleth\ShibbolethServiceProvider::class,

您必须在 app/User.php 中的 $fillable 数组中添加 unity_id

protected $fillable = [
        'unity_id', 'name', 'email',
];

您必须通过在 app/User.php 中添加以下内容来指定用户模型上的标识符

    /**
     * Get the name of the unique identifier for the user.
     *
     * @return string
     */
    public function getAuthIdentifierName()
    {
        return 'unity_id';
    }

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->unity_id;
    }

编辑 config/auth.php

'guards' => [
        'web' => [
            'driver' => 'shibboleth',
            'provider' => 'users',
        ],
],

'providers' => [
        'users' => [
            'driver' => 'shibboleth',
            'model' => App\User::class,
        ],
],

将默认用户添加到 config/services.php

'shib' => [
    'default_user' => env('APP_USER')
],

注意:由于我们正在使用Laravel的配置缓存,您需要运行 php artisan config:cache 以反映 config/services.php 中的更改

将中间件添加到 app/Http/Kernel.php

'auth.shib' => \Dfoxx\Shibboleth\AuthenticateWithShibboleth::class,

用法

当应用程序环境设置为本地时,可以在 .env 中的 APP_ENV=local 添加 APP_USER=userid 来指定您想要登录的用户。

有关使用中间件的配置路由的示例,请参阅

Route::group(['middleware' => 'auth.shib'], function() {

    Route::get('/home', 'HomeController@index');

});

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件