cornell-custom-dev/laravel-cu-auth 问题修复 & 功能扩展

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

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

cornell-custom-dev/laravel-cu-auth

Composer 安装命令:

composer require cornell-custom-dev/laravel-cu-auth

包简介

A Laravel package for authentication and identity management at Cornell University

README 文档

README

Middleware for authorizing Laravel users.

  • CUAuth SSO - Single sign-on and authorization middleware
    • SAML PHP Toolkit integration
    • Apache mod_shib integration
  • AppTesters - Limit access to users in the APP_TESTERS environment variable
  • Local Login - Allow Laravel users to log in with a local username and password
  • Livewire Auth - Block unauthenticated Livewire update requests

Use Cases

  • Single Sign-On: Protect routes with SSO (mod_shib or PHP SAML)
    • Optionally log in SSO users to app user accounts
  • AppTesters: Limit access on non-production sites to users in the APP_TESTERS environment variable

Single Sign-On

Usage

// File: routes/web.php
use CornellCustomDev\LaravelStarterKit\CUAuth\Middleware\CUAuth;

Route::group(['middleware' => [CUAuth::class]], function () {
    // Protected routes here
    Route::get('profile', [UserController::class, 'show']);
});
# File: .env
# apache-shib (default) | php-saml
CU_AUTH_IDENTITY_MANAGER=apache-shib

See Authorization for details on how to log in remote users for local authorization.

See also: shibboleth configuration.

Routing

Any pages protected by middleware are automatically redirected to SSO. To directly trigger log in or log out, use the following routes (parameters are optional and will default to '/'):

  • Login: route('cu-auth.sso-login', ['redirect_url' => '/home'])
  • Logout: route('cu-auth.sso-logout', ['return' => '/'])

Certs and Metadata (php-saml)

For using the PHP SAML Toolkit, the SAML keys and certs can be generated with the following command:

  php artisan cu-auth:generate-keys

It is possible to have composer automatically install the keys on composer install by adding the following to the scripts section of composer.json, which will only install the keys if they do not already exist:

"scripts": {
    "post-install-cmd": [
        "@php artisan cu-auth:generate-keys"
    ]
}

The default location for the SAML keys and certs is in storage/app/keys. This location is configurable in the config/cu-auth.php file or by setting the SAML_CERT_PATH in .env.

Local Testing (apache-shib)

For local testing where mod_shib is not available, the REMOTE_USER environment variable can be set to simulate Shibboleth authentication. Note that APP_ENV must be set to "local" for this to work and the config cache must be cleared when REMOTE_USER is changed.

# File: .env
APP_ENV=local
REMOTE_USER=abc123

Identity and Authorization

Once authenticated via SSO, the user's identity is available via the IdentityManager, which can be accessed via the app container.

use CornellCustomDev\LaravelStarterKit\CUAuth\Managers\IdentityManager;

$remoteIdentity = app(IdentityManager::class)->getIdentity();
$netid = $remoteIdentity->id(); // NetID | CWID

// If provided with SSO attributes:
$email = $remoteIdentity->email(); // Primary email (i.e. netid@cornell.edu)
$name = $remoteIdentity->name(); // Display name

The SAML attributes available are based on the CIT-documented list: https://it.cornell.edu/shibboleth/shibboleth-faq.

User authorization

If the site should manage authorization for users in the application, set config('cu-auth.require_local_user') to true:

# File: config/cu-auth.php
'require_local_user' => env('REQUIRE_LOCAL_USER', true),

Requiring a local user triggers the CUAuthenticated event when a user is authenticated via single sign-on. The site must register a listener for the CUAuthenticated event. This listener should look up the user in the database and log them in or create a user as needed.

AuthorizeUser is provided as a starting point for handling the CUAuthenticated event. It is simplistic and should be replaced with a site-specific implementation in the site code base. It demonstrates retrieving user data via the IdentityManager and creating a user if they do not exist.

Configuration

See config/cu-auth.php for configuration options, all of which can be set with environment variables.

To modify the default configuration, publish the configuration file:

  php artisan vendor:publish --tag=starterkit:cu-auth-config

To modify the PHP SAML Toolkit configuration, publish the configuration file:

  php artisan vendor:publish --tag=starterkit:php-saml-toolkit-config

AppTesters

Limits non-production access to users in the APP_TESTERS environment variable.

Usage

// File: routes/web.php
use CornellCustomDev\LaravelStarterKit\CUAuth\Middleware\AppTesters;
use CornellCustomDev\LaravelStarterKit\CUAuth\Middleware\CUAuth;

Route::group(['middleware' => [CUAuth::class, AppTesters::class], function () {
    Route::get('profile', [UserController::class, 'show']);
});
# File: .env
APP_TESTERS=abc123,def456

On non-production sites, the AppTesters middleware checks the "APP_TESTERS" environment variable for a comma-separated list of users. If a user is logged in and not in the list, the middleware will return an HTTP_FORBIDDEN response.

The field used for looking up users is netid by default. It is configured in config/cu-auth.php file as app_testers_field.

Local Login

For testing purposes, the environment variable "ALLOW_LOCAL_LOGIN" can be set to true to bypass the middleware for a currently authenticated user.

# File: .env
ALLOW_LOCAL_LOGIN=true

Livewire Auth

Blocks unauthenticated POST requests to /livewire/update, preventing anonymous users from interacting with Livewire components.

Usage

# File: .env
REQUIRE_LIVEWIRE_AUTH=true

cornell-custom-dev/laravel-cu-auth 适用场景与选型建议

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

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

围绕 cornell-custom-dev/laravel-cu-auth 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-14