codeedu / laravel-sso
该软件包已被放弃,不再维护。未建议替代软件包。
关于该软件包最新版本(dev-master)没有可用的许可证信息。
dev-master
2019-11-21 18:20 UTC
Requires
- php: ^7.1.3
- guzzlehttp/guzzle: ~6.0
- illuminate/cache: ~5.5
- illuminate/cookie: ~5.5
- illuminate/routing: ~5.5
- illuminate/session: ~5.5
- illuminate/validation: ~5.5
- jasny/sso: ^0.3.0
This package is auto-updated.
Last update: 2021-04-21 22:03:48 UTC
README
此库提供了Laravel框架与SSO(单点登录)的集成 https://en.wikipedia.org/wiki/Single_sign-on。
开始使用
安装
在shell中执行
composer require codeedu/laravel-sso:0.0.1
发布sso配置文件
php artisan vendor:publish --provider="CodeEdu\LaravelSso\SSOServiceProvider"
代理配置
设置环境变量
SSO_SERVER=http://server.address
SSO_BROKER_ID=BROKER ID
SSO_BROKER_SECRET=BROKER SECRET
在Kernel.php
中的routes
键中注册中间件 CodeEdu\LaravelSso\Middleware\AttachBroker。
在config/auth.php
中注册 sso。
'sso' => [ 'driver' => 'sso', 'model' => \App\User::class ]
服务器配置
设置环境变量
SSO_TYPE=server
创建App\Sso\Server.php
<?php namespace App\Sso; use CodeEdu\LaravelSso\Server as SsoServer; use Jasny\ValidationResult; use App\Models\User; class Server extends SsoServer { private $brokers = [ '1' => 'secret1', '2' => 'secret2' ]; /** * Authenticate using user credentials * * @param string $username * @param string $password * @return \Jasny\ValidationResult */ protected function authenticate($username, $password) { if (!\Auth::guard('web')->validate(['email' => $username, 'password' => $password])) { return ValidationResult::error(trans('auth.failed')); } return ValidationResult::success(); } /** * Get the secret key and other info of a broker * * @param string $brokerId * @return array */ protected function getBrokerInfo($brokerId) { return !array_key_exists($brokerId, $this->brokers) ? null : [ 'id' => $brokerId, 'secret' => $this->brokers[$brokerId] ]; } /** * Get the information about a user * * @param string $username * @return array|object */ protected function getUserInfo($username) { $user = User::whereEmail($username)->first(); return !$user ? null : [ 'user' => $user, ]; } }
此文件将描述服务器SSO身份验证和代理的验证方式。更多详情请查看:https://github.com/jasny/sso