定制 fereydooni/laravel-sso 二次开发

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

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

fereydooni/laravel-sso

Composer 安装命令:

composer require fereydooni/laravel-sso

包简介

A robust Single Sign-On (SSO) system for Laravel

README 文档

README

A robust Single Sign-On (SSO) system for Laravel applications using Laravel Passport for OAuth2 authentication, with optional social media authentication via Laravel Socialite and two-factor authentication (2FA).

Features

  • OAuth2 authentication using Laravel Passport
  • Social media login via Laravel Socialite (Google, Facebook, Twitter, GitHub)
  • Two-factor authentication via SMS and email channels
  • Vue.js-based admin panel for managing OAuth2 applications
  • Dedicated authentication page
  • Support for SSO across multiple Laravel applications

Requirements

  • PHP 8.1+
  • Laravel 10.x
  • Laravel Passport 11.x
  • Laravel Socialite 5.x
  • Vue 3.x (for admin panel and authentication page)

Installation

1. Composer Installation

composer require fereydooni/laravel-sso

2. Publish Configuration

php artisan vendor:publish --provider="Fereydooni\LaravelSso\SSOAuthServiceProvider"

3. Run Migrations

php artisan migrate

4. Set Up Laravel Passport

php artisan passport:install

5. Set Up Socialite Providers (Optional)

Add your Socialite provider credentials to the config/sso-auth.php configuration file.

6. Set Up Vue.js Components (Optional)

npm install
npm run dev

Configuration

Edit the config/sso-auth.php file to customize:

  • OAuth2 settings
  • Socialite providers
  • Two-factor authentication
  • Admin panel settings

Usage

Basic Usage with Attributes

use Fereydooni\LaravelSso\Attributes\SSOAuth;
use Fereydooni\LaravelSso\Attributes\TwoFactorChannel;
use Fereydooni\LaravelSso\SSOManager;

#[SSOAuth(provider: 'oauth2', scopes: ['read', 'write'], twoFactor: true)]
#[TwoFactorChannel(channel: 'email', priority: 1)]
class AuthController extends Controller
{
    public function login(Request $request)
    {
        $manager = app(SSOManager::class);
        $user = $manager->authenticate('oauth2', $request);
        
        if ($manager->requiresTwoFactor($user)) {
            $manager->sendTwoFactorCode($user, 'email');
            return redirect()->route('2fa.verify');
        }
        
        return $manager->generateToken($user);
    }
}

Social Authentication

#[SSOAuth(provider: 'socialite:google', scopes: ['profile'], twoFactor: true)]
#[TwoFactorChannel(channel: 'sms', priority: 1)]
public function googleLogin(Request $request)
{
    $manager = app(SSOManager::class);
    return $manager->redirectToProvider('google');
}

public function googleCallback(Request $request)
{
    $manager = app(SSOManager::class);
    $user = $manager->handleProviderCallback('google', $request);
    
    if ($manager->requiresTwoFactor($user)) {
        $manager->sendTwoFactorCode($user, 'sms');
        return redirect()->route('2fa.verify');
    }
    
    return $manager->generateToken($user);
}

Admin Panel

Access the admin panel at /sso/admin to manage your OAuth2 clients.

Authentication Page

Direct users to /sso/login for the authentication page.

Testing

composer test

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This package is open-sourced software licensed under the MIT license.

fereydooni/laravel-sso 适用场景与选型建议

fereydooni/laravel-sso 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 fereydooni/laravel-sso 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fereydooni/laravel-sso 我们能提供哪些服务?
定制开发 / 二次开发

基于 fereydooni/laravel-sso 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-24