keith-ferney / laravel-shibboleth
为Laravel 5.x启用基本的Shibboleth支持
Requires
- illuminate/support: 5.*
- laravel/framework: 5.4.* || 5.5.*
- mrclay/shibalike: 1.0.0
- tymon/jwt-auth: ^0.5.10
Requires (Dev)
- orchestra/testbench: 3.4.*
- phpunit/phpunit: ^6.0
This package is auto-updated.
Last update: 2024-09-12 10:42:23 UTC
README
此包为Laravel提供Shibboleth认证。
为了开发,它可以通过mrclay/shibalike模拟IdP。
先决条件
为了使用此插件,我们假设您已经配置了一个现有的Shibboleth SP和Shibboleth IdP。以下内容不会(且不会)解释如何设置这些。
但是,这可能有帮助:https://github.com/razorbacks/ubuntu-authentication/tree/master/shibboleth
安装
使用composer将最新版本要求到您的项目中
composer require razorbacks/laravel-shibboleth
如果您正在运行Laravel >= 5.5,则可以跳过此步骤,否则您需要在您的config/app.php
文件中的Providers
数组中手动注册服务提供者。
StudentAffairsUwm\Shibboleth\ShibbolethServiceProvider::class,
如果您想通过shibalike使用模拟的IdP,那么您需要在任何版本上手动注册它 - 即使在Laravel 5.5中也不会自动加载。
StudentAffairsUwm\Shibboleth\ShibalikeServiceProvider::class,
注意 shibalike的密码与用户名相同。
发布默认配置文件
php artisan vendor:publish --provider="StudentAffairsUwm\Shibboleth\ShibbolethServiceProvider"
可选地,您还可以发布shibalike模拟IdP登录的视图
php artisan vendor:publish --provider="StudentAffairsUwm\Shibboleth\ShibalikeServiceProvider"
阿肯色大学用户
要使用IdP登出,请在
config/shibboleth.php
中设置以下内容'idp_logout' => '/Shibboleth.sso/Logout?return=https%3A%2F%2Fidp.uark.edu%2Fidp%2Fexit.jsp',
在您的config/auth.php
文件中将驱动器更改为shibboleth
。
'providers' => [ 'users' => [ 'driver' => 'shibboleth', 'model' => App\User::class, ], ],
现在,用户可以通过访问https://example.com/shibboleth-login
通过Shibboleth登录,并使用https://example.com/shibboleth-logout
登出,这样您可以根据登录表单中的电子邮件地址提供自定义链接或重定向。
@if (Auth::guest()) <a href="/shibboleth-login">Login</a> @else <a href="/shibboleth-logout"> Logout {{ Auth::user()->name }} </a> @endif
您可以在config/shibboleth.php
中配置服务器变量映射,例如用户的首字母、姓氏、权利等。您可以通过阅读认证后填充到$_SERVER
变量的内容来查看它们。
<?php print_r($_SERVER);
映射的值将在认证成功后同步到用户表中。
声明登录路由
根据惯例,laravel假定存在一个名为login
的路由以重定向未认证的请求。
此包将其路由命名为shibboleth-login
,因为它旨在与其他认证提供者协同工作,例如由artisan提供的默认脚手架。但如果这是唯一的认证提供者,则需要手动声明该名称。例如:
Route::name('login')->get('/login', '\\'.Route::getRoutes()->getByName('shibboleth-login')->getActionName());
或更易于阅读,但带有重定向
Route::redirect('/login', '/shibboleth-login')->name('login');
另请参阅:razorbacks#10
授权
您可以静态地检查当前用户的权利字符串
$entitlement = 'urn:mace:uark.edu:ADGroups:Computing Services:Something'; if (Entitlement::has($entitlement)) { // authorize something }
现在您可以在这些权利周围制定策略和门。
本地用户
这旨在与本地认证系统协同工作,适用于您想要同时拥有Shibboleth和本地用户的项目的项目。如果您想允许本地注册并认证Shibboleth用户,则请使用laravel内置的认证系统。
php artisan make:auth
JWTAuth令牌
如果您正在使用 tymon/jwt-auth 进行令牌认证,请在您的 .env
文件中设置此变量
JWTAUTH=true