PHPackages                             wangyongdong/laravelcas - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. wangyongdong/laravelcas

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

wangyongdong/laravelcas
=======================

This is a laravel phpcas extension

1.0.5(2y ago)06MITPHPPHP &gt;=5.4.0CI failing

Since Sep 28Pushed 2y ago1 watchersCompare

[ Source](https://github.com/wangyongdong/laravelcas)[ Packagist](https://packagist.org/packages/wangyongdong/laravelcas)[ RSS](/packages/wangyongdong-laravelcas/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (3)Versions (6)Used By (0)

laravel-cas
===========

[](#laravel-cas)

Laravel Cas Client 服务是基于 [phpCas](https://github.com/apereo/phpCAS) 基础上进行封装

支持
--

[](#支持)

- `laravel5.5+`
- `laravel6.x`
- `laravel7.x`
- `laravel8.x`

### 版本说明

[](#版本说明)

- 当前版本稳定版本为 [laravel-cas 1.0.4](https://github.com/wangyongdong/laravelcas)
    - `1.0.3` 更新同步退出的问题
    - `1.0.4` 更新 debug 日志打印功能
    - 此版本改动较大，需更新老版本代码
    - `1.0.5` 更改 auth 后回跳附带端口的问题

安装
--

[](#安装)

### 编辑 `Composer.json`

[](#编辑-composerjson)

```
{
    "repositories": {
        "wangyongdong/phpcas": {
            "type": "git",
            "url": "https://github.com/wangyongdong/phpCAS.git"
        },
        "wangyongdong/laravelcas": {
            "type": "git",
            "url": "https://github.com/wangyongdong/laravelCas.git"
        }
    },
    "require": {
      "wangyongdong/laravelcas": "^3.0"
    },
    "config": {
        "secure-http": false
    }
}
```

### 执行安装

[](#执行安装)

- `composer install` 或 `composer require "wangyongdong/laravelcas:1.0.4"`

### 配置 `provider` 和 `aliases`

[](#配置-provider-和-aliases)

> NOTE : 该软件包支持Laravel 5.5的自动发现功能，因此，如果您使用的是Laravel 5.5，则可以跳过本节。

#### 1. 配置 `provider `

[](#1-配置-provider-)

`'providers' => [ Wangyongdong\LaravelCas\CasServiceProvider::class ],`

#### 2. 配置 `aliases`

[](#2-配置-aliases)

`'aliases' => [ ...  'Laravelcas' => Wangyongdong\LaravelCas\Facades\Cas::class, ],`

### 发布配置文件

[](#发布配置文件)

`php artisan vendor:publish --provider="Wangyongdong\LaravelCas\CasServiceProvider"`

#### 配置文件

[](#配置文件)

发布完成后，将自动生成一个名为 `config/cas.php` 的配置文件。

一般来说，仅需配置一下几项即可

- 配置 `laravel` 项目根目录下 `.env`文件，修改 `APP_URL` 的值
- `CAS_HOST`: CAS服务端主域名
- `CAS_CONTENT`: CAS服务路径名称
- `CAS_PORT`: CAS服务端口
- `CAS_LOGOUT_URL`: CAS服务退出url地址
- `CAS_REAL_HOSTS`: 同 `CAS_HOST`

更多配置项在文件 `config/cas.php` 中查看

### 使用中间件

[](#使用中间件)

如果要将CAS服务用作身份验证的中间件，则可以在 `app/Http/Kernel.php`中的 `$routeMiddleware` 对其进行配置。

```
'LaravelCasMiddleware' => \Wangyongdong\LaravelCas\Middleware\CASAuth::class,
```

```
Route::group(['middleware' => ['LaravelCasMiddleware']], function () {
    Route::get('/login/auth', function (Illuminate\Http\Request $request) {
        $user = $request->userid;
        dd($user);
    });
});
```

### Laravel 必须配置项

[](#laravel-必须配置项)

- 若同步退出时 CAS 服务器请求地址为根目录则需要做如下修改：

1. 路由修改支持post，示例：`Route::any('/', 'HomeController@index')->name('home.index');`
2. http 419问题，[参考链接](https://blog.csdn.net/u011415782/article/details/77676632)
    1. 在 `app\Http\Kernel.php` 中，注释 `VerifyCsrfToken` 中间件
    2. 添加白名单， `app\Http\Middleware\VerifyCsrfToken.php` 文件中

    ```
    protected $except = [
       '/'
    ];
    ```
3. 具体目录根据请求地址来调整

### 支持方法

[](#支持方法)

- 验证是否登录 `LaravelCas::checkAuthentication()`
- 强制执行登录 `LaravelCas::forceAuthentication()`
- 获取登录地址 `LaravelCas::login_url()`
- 获取退出地址 `LaravelCas::logout_url()`
- 执行退出 `LaravelCas::logout($service = '')`
- 获取当前登录用户id `LaravelCas::user()`
- Laravel项目获取登陆用户id：`$request->userid` or `$request->session()->get('userid')`

Updates
-------

[](#updates)

- 支持 `laravel6.x` `laravel7.x` `laravel8.x`
- 更新版本 [phpCAS 1.3.9](https://apereo.github.io/phpCAS/)，解决 `phpCAS error: phpCAS::client(): ErrorException: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?` 问题
- 兼容 `composer2.0`，优化命名空间
- 支持重定向注销登陆
- 添加支持中间件的使用
- 更新包 [phpCAS](https://github.com/wangyongdong/phpCAS.git)，兼容 `http` 和 `https`的判断
- 支持配置文件，对 `phpCAS` 客户端进行配置

问题
--

[](#问题)

1. `Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE)`

- 报错版本：`laravel5.5` `php7.0.9`
- 问题原因：包 `symfony/translation` 使用 `php7.1` 新增特性 [可为空（Nullable）类型](https://www.php.net/manual/zh/migration71.new-features.php) 导致报错
- 解决办法：升级 `laravel` 版本，或升级 `php` 版本

2. `Declaration of Illuminate\Container\Container::get($id) must be compatible with Psr\Container\ContainerInterface::get(string $id) in`

- 报错版本：
    - `laravel5.6` `php7.1.9`
    - `laravel5.7` `php7.1.9`
    - `laravel5.8` `php7.1.9`
- 问题原因：因 `laravel5.6+` 版本中引用的扩展包里，使用了 `php7.2` 新特性 参数类型声明，导致报错
- 解决办法：
    - 1. 升级到 `php7.2+`
    - 2. 修改`Illuminate\Container\Container` 592行，161行。改为 `public function get(string $id)`，`public function has(string $id)`

3. laravel 不能同步退出问题

Links
-----

[](#links)

[PHPCAS](https://github.com/apereo/phpCAS)

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~507 days

Total

5

Last Release

803d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13379335?v=4)[wangyongdong](/maintainers/wangyongdong)[@wangyongdong](https://github.com/wangyongdong)

---

Top Contributors

[![wangyongdong](https://avatars.githubusercontent.com/u/13379335?v=4)](https://github.com/wangyongdong "wangyongdong (26 commits)")

---

Tags

phplaravelauthcasphpCAS

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wangyongdong-laravelcas/health.svg)

```
[![Health](https://phpackages.com/badges/wangyongdong-laravelcas/health.svg)](https://phpackages.com/packages/wangyongdong-laravelcas)
```

###  Alternatives

[cartalyst/sentinel

PHP 8.2+ Fully-featured Authentication &amp; Authorization System

1.6k2.7M76](/packages/cartalyst-sentinel)[xavrsl/cas

Add CAS server SSO authentication to Laravel 4 and 5

7637.1k](/packages/xavrsl-cas)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
