razorbacks / 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 not auto-updated.
Last update: 2024-09-15 02:52:12 UTC
README
此包为 Laravel 提供Shibboleth 身份验证。
在开发中,它可以 模拟 一个 IdP(通过 mrclay/shibalike)。
先决条件
为了使用此插件,我们假设您已经配置了现有的 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');
参见: #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