定制 sobiz/laravel-sso 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sobiz/laravel-sso

Composer 安装命令:

composer require sobiz/laravel-sso

包简介

Single Sign-On package for Sobiz applications using OAuth 2.0 + OIDC

README 文档

README

A lightweight Single Sign-On (SSO) package for Laravel applications, enabling seamless authentication with Sobiz MyProfile (OAuth 2.0 + OIDC).

Features

  • Easy installation and configuration.
  • Seamless integration with Sobiz SSO server.
  • Built-in middleware for protecting routes.
  • Pre-configured login buttons and views.
  • Clean uninstallation process.

Requirements

  • PHP ^8.1
  • Laravel ^10.0 or ^11.0

Installation

1. Install the package via composer

composer require sobiz/laravel-sso

2. Run the installation command

The installation command will publish the configuration file, migrations, and views. It will also add the necessary environment variables to your .env file.

php artisan sso:install

3. Register your application

Go to Sobiz MyProfile Admin and register your application to get your Client ID and Client Secret.

4. Update your .env file

Ensure the following variables are correctly set in your .env file:

SSO_AUTH_SERVER_URL=https://myprofile.sobiz.com
SSO_CLIENT_ID=your-client-id
SSO_CLIENT_SECRET=your-client-secret
SSO_REDIRECT_URI=https://your-app.com/auth/sso/callback
SSO_SESSION_DOMAIN=your-app-domain.com

Usage

Middleware

Protect your routes using the sso.auth middleware:

Route::middleware(['sso.auth'])->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index']);
});

Login Button

Add the pre-styled SSO login button to your login page:

@include('sso::login-button')

SSO Facade

You can use the SSO facade to access user information or handle logout:

use Sobiz\LaravelSSO\Facades\SSO;

// Get the authenticated SSO user
$user = SSO::user();

// Logout
SSO::logout();

Uninstallation

To remove the package resources (config, views, migrations, and environment variables) from your application, run:

php artisan sso:uninstall

Warning

This command will delete published files and remove SSO variables from your .env. If you have already run migrations, remember to roll them back manually before running this command if you wish to remove the database tables.

After running the uninstall command, you can remove the package from composer:

composer remove sobiz/laravel-sso

Troubleshooting

  • Invalid state parameter: Ensure that your SESSION_DOMAIN in .env matches the domain you are visiting, and that your APP_URL matches your actual serving URL (including port if on localhost).
  • Redirection loop: Check if the SSO_REDIRECT_URI is correctly registered in both your application .env and the MyProfile admin portal.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 41
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-16