gigabait/laravel-sso 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

gigabait/laravel-sso

最新稳定版本:v1.0.2

Composer 安装命令:

composer require gigabait/laravel-sso

包简介

Laravel library for implementing SSO authorizations

README 文档

README

Latest Version on Packagist Total Downloads

Laravel SSO

Laravel SSO is a package for implementing Single Sign-On (SSO) authorizations in your Laravel project. This package allows you to authorize users on a Laravel panel from another website.

Requirements

  • PHP 7.3 or higher
  • Laravel 8.0 or higher

Installation

To install the package, use Composer:

composer require gigabait/laravel-sso

Configuration

  1. Publish the configuration file by running the following command:
php artisan vendor:publish --tag=sso

This command will publish the config/sso.php file, where you can set the secret key for SSO authorization.

  1. Set the secret key in your .env file:
SSO_SECRET_KEY=your_secret_key

Make sure the secret key is 32 characters long.

Usage

  1. To authorize users on the Laravel panel from another website, first perform SSO authorization on your website.
  2. Redirect the user to the /sso-login route with a GET parameter auth_marker containing the encrypted user data in JSON format. For example:
use Illuminate\Encryption\Encrypter;

public function redirectToAppB()
{
    $user = Auth::user();
    $authMarkerData = [
        'email' => $user->email,
        'secret_key' => config('sso.secret_key')
    ];

    $key = config('sso.secret_key');
    $cipher = config('app.cipher');
    $encrypter = new Encrypter($key, $cipher);
    $token = json_encode($authMarkerData);
    $encryptedToken = $encrypter->encrypt($token);

    header("Location: https://app-b.example.com/sso-login?token=" . urlencode($encryptedToken));
}

After being redirected to the /sso-login route, the user will be automatically authorized on the Laravel panel if their email address matches a record in the database.

Note

Make sure both applications use the same SSO_SECRET_KEY in their respective .env files. This is required for the encryption and decryption process to work correctly. The key must be 32 characters long.

Error Handling

If an error occurs during the SSO process, the user will be redirected to the login page of App B. If the secret key length is not 32 characters, an error message will be displayed.

Support

If you have any questions or issues, please create a new issue in the project repository on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固